Совместное использование объекта на экранах с помощью Spring Webflow
Я пытаюсь настроить что-то, что будет похоже на многоэкранный процесс настройки бронирования, например.
Экран 1 Добавить личную информациюЭкран 2 Контактная информацияЭкран 3 Сводка и подтверждениеЯ настроил свой .jsp и xml webflow и все классы, но у меня проблемы с их связыванием. Я хочу создать класс Account в начале потока. Когда первый экран заполнен, информация сохраняется в этом классе. Когда на последнем экране пользователь может просматривать сводку на основе предоставленной им информации и при необходимости вносить изменения, когда он возвращается к первому экрану, информация уже будет заполнена для него, поэтому ему не нужно повторно вводить.
Я прошу прощения за стену кода. Я пытался свести это к возможным местам для ошибки, о которой я мог думать.
Мой поток-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>
Мой общий сервлет-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");
}
}
так что в моих сценариях Java для первого экрана у меня будет что-то вроде:
<form:form modelAttribute="booking" action="${flowExecutionUrl}" method="post">
<form:input type="text" path="username"/>
</form:form>
и после запроса к следующему экрану я хочу вернуть значение в сводке, например
<form:form modelAttribute="booking" action="${flowExecutionUrl}" method="post">
<spring:bind path="username">${status.value}</spring:bind>
</form:form>
Я получаю сообщение об ошибке:
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'
Я попробовал другой способ сделать все это, определяя bean-компонент в моем сервлете следующим образом:
<beans:bean id="bookingBean" class="com.mycompany.myapp.BookingIpl" scope="prototype" />
но это тоже не помогло, выдало ту же ошибку.
Я очень новичок в веб-потоке и весне, поэтому, пожалуйста, прости меня, если ошибка, которую я сделал, была чем-то очевидным.
Спасибо