我正在开发一个在特定时刻使用Spring Web Flow的网站。在该流程中,有一个点(flow2.jsp),要求用户从一些复选框中进行选择。我看到的所有示例(如this和this)都获取了来自Controller类的复选框的项目......但由于我使用的是Spring Web Flow,因此我使用的是默认的flowController:
<beans:bean id="flowcontroller" class="org.springframework.webflow.mvc.servlet.FlowController">
<beans:property name="flowExecutor" ref="flowExecutor"></beans:property>
</beans:bean>
我怎么能喂这些东西?我必须在JSP中对它们进行硬编码吗?
谢谢。
修改
我最终做了类似的事情,使用我的模型对象来初始化Map:
public Map referenceData(RequestContext context){
System.out.println("Setting up list");
Map referenceData=new HashMap();
list=new ArrayList<String>();
list.add("cb1");
list.add("cb2");
list.add("cb3");
referenceData.put("list", list);
return referenceData;
}
从flow.xml调用此方法:
<view-state id="flow2" view="flow2" model="proyecto">
<on-render>
<evaluate expression="proyecto.referenceData(flowRequestContext)"></evaluate>
</on-render>
<transition on="gotoPageThree" to="flow3"></transition>
<transition on="goBack" to="inicio"></transition>
</view-state>
flow2.jsp是视图的名称:
<form:checkboxes items="${list}" path="property-in-my-model"/>
这样就抛出了异常:
java.lang.IllegalArgumentException: 'items' must not be null
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.web.servlet.tags.form.AbstractMultiCheckedElementTag.setItems(AbstractMultiCheckedElementTag.java:83)
at org.apache.jsp.WEB_002dINF.views.flow2_jsp._jspx_meth_form_005fcheckboxes_005f0(flow2_jsp.java:170)
at org.apache.jsp.WEB_002dINF.views.flow2_jsp._jspx_meth_form_005fform_005f0(flow2_jsp.java:135)
at org.apache.jsp.WEB_002dINF.views.flow2_jsp._jspService(flow2_jsp.java:81)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
at org.springframework.webflow.mvc.servlet.ServletMvcView.doRender(ServletMvcView.java:55)
at org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:187)
at org.springframework.webflow.engine.ViewState.render(ViewState.java:296)
at org.springframework.webflow.engine.ViewState.refresh(ViewState.java:243)
at org.springframework.webflow.engine.ViewState.resume(ViewState.java:221)
at org.springframework.webflow.engine.Flow.resume(Flow.java:545)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:258)
at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169)
at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183)
at org.springframework.webflow.mvc.servlet.FlowController.handleRequest(FlowController.java:174)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
我可以看到sysout出现在控制台之前,而不是Exception,所以我的模型对象应该有一个可以使用的列表......
答案 0 :(得分:0)
Flow控制器是Spring MVC Controller层和Spring Web Flow引擎之间的适配器。它允许Spring Web Flow作为Controller在DispatcherServlet中运行。流控制器确定在请求到达时要执行的操作,如启动新流程执行,恢复暂停流程执行,停止流程执行。 它不会处理表单元素。
您需要创建一个类(比如登录,登录服务类),在进入流程的下一个屏幕之前处理与表单相关的内容。
例如,创建一个Class来处理登录流程操作:
public class LoginAction implements Seerilaizable{
...
public void performPostLoginProcess(LoginForm loginForm){
..
}
}
创建一个表单来保存视图中定义的表单字段(通常我只使用一个表单来处理具有多个视图的整个流程,但根据需求,我们每个流程可以有多个表单):
public class LoginForm implements Seerilaizable{
//Your jsp view has these fields
private boolean checkBox1;
private String textField1;
...
}
在调度程序servlet上下文中定义此bean,如:
<bean id="loginAction" class="package.LoginAction">
<property>...</property>
<bean>
在您的流程中:
<start-state id="initializeLoginFlow">
<action-state id="initializeLoginFlow">
<evaluate expression="LoginAction.initializeFormObject(flowRequestContext)" result="flowScope.loginForm" />
<transition to="login" />
</action-state>
<view-state id="login" view="login" model="loginForm">
<transition on="submit" to="section1">
<evaluate expression="loginAction.performPostLoginProcess(flowScope.loginForm)"></evaluate>
</transition>
</view-state>
<view-state id="section1" view="section1" model="loginForm">
...
这样你需要有一个服务类来处理流量需求。希望这可以帮助。
Edit1:在表单proyecto中包含List webFrameworkList。将参考数据更改为
public void referenceData(Proyecto proyecto){
System.out.println("Setting up list");
List<String> list=new ArrayList<String>();
list.add("cb1");
list.add("cb2");
list.add("cb3");
proyecto.setWebFrameworkList(list);
}
在jsp中:
td>
<form:checkboxes items="${webFrameworkList}" path="checkBoxPropertyInModel" />
</td>