Compartilhando objeto entre telas, usando o Spring Webflow
Estou tentando criar algo que se pareça com um processo de várias telas para configurar uma reserva, por exemplo.
Tela 1 Adicione informações pessoaisTela 2 Informações de contatoTela 3 Resumo e confirmeEu configurei meu webflow .jsp e xml e todas as classes, mas estou tendo problemas para vinculá-las. Eu quero criar uma classe de conta no início do fluxo. Quando a primeira tela é preenchida, as informações são armazenadas nessa classe. Quando na tela final, o usuário pode visualizar o resumo com base nas informações que ele forneceu e revisar, se necessário, quando ele voltar para a primeira tela, as informações serão preenchidas para ele, para que ele não tenha que entrar novamente.
Sinto muito pela parede do código. Tentei minimizá-lo para os possíveis lugares para um erro que eu poderia pensar.
Meu 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>
Meu servlet-context.xml geral
<?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");
}
}
então nos meus scripts java para a primeira tela eu teria algo como:
<form:form modelAttribute="booking" action="${flowExecutionUrl}" method="post">
<form:input type="text" path="username"/>
</form:form>
e após o prompt para a próxima tela eu quero retornar o valor em um resumo por exemplo
<form:form modelAttribute="booking" action="${flowExecutionUrl}" method="post">
<spring:bind path="username">${status.value}</spring:bind>
</form:form>
O erro que estou recebendo é ao longo da linha de:
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'
Eu tentei outro método para fazer tudo isso que está definindo um bean no meu servlet da seguinte forma:
<beans:bean id="bookingBean" class="com.mycompany.myapp.BookingIpl" scope="prototype" />
mas isso não ajudou, deu o mesmo erro.
Eu sou muito novo no fluxo da web e na primavera, então, por favor, me perdoe se o erro que cometi foi algo óbvio.
Obrigado