Udostępnianie obiektu na różnych ekranach za pomocą Spring Webflow
Próbuję skonfigurować coś, co będzie wyglądało na przykład proces wielostronicowego konfigurowania rezerwacji.
Ekran 1 Dodaj informacje osobisteEkran 2 Informacje kontaktoweEkran 3 Podsumowanie i potwierdźSkonfigurowałem mój przepływ internetowy .jsp i xml i wszystkie klasy, ale mam problemy z ich łączeniem. Chcę utworzyć klasę konta na początku przepływu. Po wypełnieniu pierwszego ekranu informacje są zapisywane w tej klasie. Kiedy na ostatnim ekranie użytkownik może wyświetlić podsumowanie na podstawie podanych przez siebie informacji i, jeśli to konieczne, skorygować je, kiedy wróci do pierwszego ekranu, informacje zostaną wypełnione już dla niego, aby nie musiał ponownie wchodzić.
Przepraszam za ścianę kodu. Starałem się zminimalizować to do możliwych miejsc dla błędu, który mogłem wymyślić.
Mój plik flow-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<on-start>
<evaluate expression="BookingManagementService.createBooking()" result="flowScope.booking" />
</on-start>
<view-state id="flow-config" view="booking/BookingIdentificationScreen" model="booking">
<binder>
<binding property="username" />
</binder>
<transition on="next" to="enterContactDetails"/>
<transition on="cancel" to="cancel"/>
</view-state>
...
</flow>
Mój ogólny servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:webflow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">
<annotation-driven />
<resources mapping="/resources/**" location="/resources/" />
<beans:bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.mycompany.myapp" />
<beans:bean id="handlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<beans:bean name="/index.do" class="com.mycompany.myapp.IndexController" />
<beans:bean name="/home.do" class="com.mycompany.myapp.HomeController" />
<beans:bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<beans:property name="mappings" value="/account/flow-config.do=flowController" />
<beans:property name="alwaysUseFullPath" value="true"/>
</beans:bean>
<!-- SPRING WEB FLOW STUFF -->
<beans:bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
<beans:property name="flowExecutor" ref="flowExecutor"/>
</beans:bean>
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry"/>
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path="/WEB-INF/config/flow-config.xml"/>
</webflow:flow-registry>
<webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="viewFactoryCreator"/>
<beans:bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<beans:property name="viewResolvers">
<beans:list>
<beans:ref bean="viewResolver"/>
</beans:list>
</beans:property>
</beans:bean>
</beans:beans>
BookingManagementService.java
@Service("bookingService")
public class BookingManagementService{
@Transactional(readOnly = true)
public BookingIpl createBooking(Long hotelId, String username) {
BookingIpl booking= new BookingIpl();
return booking;
}
}
BookingIpl.java
@Entity
public class BookingIpl implements Serializable {
public String username;
...
}
IndexController
@Controller
public class IndexController extends AbstractController {
private BookingManagementService bookingService;
@Autowired
public IndexController(BookingManagementService bookingService) {
this.bookingService = bookingService;
}
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
return new ModelAndView("index");
}
}
więc w moich skryptach java na pierwszym ekranie miałbym coś takiego:
<form:form modelAttribute="booking" action="${flowExecutionUrl}" method="post">
<form:input type="text" path="username"/>
</form:form>
a po monicie do następnego ekranu chcę na przykład zwrócić wartość w podsumowaniu
<form:form modelAttribute="booking" action="${flowExecutionUrl}" method="post">
<spring:bind path="username">${status.value}</spring:bind>
</form:form>
Błąd, który otrzymuję, jest zgodny z:
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/myapp] threw exception [Request processing failed; nested exception is org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@778e65f2 targetAction = [EvaluateAction@25c73030 expression = bookingService.createBooking(), resultExpression = flowScope.booking], attributes = map[[empty]]] in state 'null' of flow 'flow-config' -- action execution attributes were 'map[[empty]]'] with root cause
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'bookingService' cannot be found on object of type 'org.springframework.webflow.engine.impl.RequestControlContextImpl'
Próbowałem innej metody, aby zrobić to wszystko, co definiuje fasolę w moim serwletu w taki sposób:
<beans:bean id="bookingBean" class="com.mycompany.myapp.BookingIpl" scope="prototype" />
ale to też nie pomogło, dał ten sam błąd.
Jestem bardzo nowa w przepływie internetowym i wiosennym, więc proszę mi wybaczyć, jeśli popełniony przeze mnie błąd był czymś oczywistym.
Dziękuję Ci