假设您的web.xml中的映射为:
<servlet> <servlet-name>yourApp</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value></param-value> </init-param> <load-on-startup>1</load-on-startup></servlet><servlet-mapping> <servlet-name>yourApp</servlet-name> <url-pattern>*.htm</url-pattern></servlet-mapping>
在servlet xml文件中定义以下内容(在web.xml上方定义yourApp-Servlet.xml):
<!--Handler mapping for your controller which does some work per your requirements--> <bean id="urlMapping" > <property name="order" value="1" /> <property name="mappings"> <props> <prop key="/handledByController.htm">yourController</prop> </props> </property> </bean> <!--Your controller bean definition--> <bean id="yourController" > //some properties like service reference </bean> <!--Class which handles the flow related actions--> <bean id="classForThisFlow" > </bean>
我假设您在webflowconfig xml中定义了如下所示的Web流所需配置(对于Webflow 2.3-1种配置几乎没有什么不同):
<!--View resolvers--> <bean id="internalResourceViewResolver" > <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <bean id="flowViewResolver" > <property name="viewResolvers" ref="internalResourceViewResolver"/> </bean> <!--flow xml registration - flow xmls are in flows folder--> <flow:registry id="flowRegistry"> <flow:location path="/WEB-INF/flows*-flow.xml" /> </flow:registry> <!--Flow controller to which dispacther servlet delegates the control to manage flow execution--> <bean name="flowController" > <property name="flowExecutor" ref="flowExecutor" /> </bean> <flow:executor id="flowExecutor" registry-ref="flowRegistry"> <flow:repository type="continuation" max-conversations="1" max-continuations="30" /> <flow:execution-listeners> <flow:listener ref="listener"/> </flow:execution-listeners> </flow:executor> <!--validator to be identified and registered for view state validations if enabled--> <bean name="validator" /> <flow:flow-builder-services id="flowBuilderServices" view-factory-creator="flowViewResolver" validator="validator"/>
在流xml中,您的查看方式如下:
<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.3.xsd"start-state="prepareFlow"><action-state id="prepareFlow"> <evaluate expression="classForThisFlow.prepareFlowForm()" result="flowScope.client"/> <transition to="clientOptions" /></action-state> <view-state id="clientOptions" view="options" model="client"> <!--If you have defined validator for the action class handling this view, then validation will kick in. You can disable validation by validate="false"--> <!--By default binding of form fields will happen to the model specified; you can disable it by bind="false"--> <transition on="submit" to="/confirm/i"/> <transition on="back" to="viewCart"/> </view-state> <action-state id="/confirm/i"> <!--Do some action on the form--> <evaluate expression="classForThisFlow.methodName(flowRequestContext,flowScope.client)"/> <transition to="returnToController" /> </action-state> <!--This will take the control back to yourController; See mappingis specified as *.htm in web.xml--> <end-state id="returnToController" view="externalRedirect:handledByController.htm" />
您可以通过以下方式将客户端通过会话传递给控制器:
public class ClassForThisFlow{ public Client prepareFlowForm(){ Client client= new Client(); ... return client; } public void methodName(RequestContext context, Client client){ HttpSession session = ((HttpServletRequest)context.getExternalContext().getNativeRequest()).getSession(); session.setAttribute("client",client); } ..... }这样,您就可以在流程中导航并在提交“确认”时将您带到操作类,如果需要的话,否则请同时更改最终状态ID和提交时的过渡到“确认”,这会将控件定向到yourController
。在控制器中,您可以访问会话并重新绑定客户端对象以进行进一步处理。



