Results 1 to 3 of 3

Thread: Reference a flowScope as a modelAttribute in Spring MVC <form:form> tag>

  1. #1
    Join Date
    Feb 2010
    Location
    United States
    Posts
    4

    Default Reference a flowScope as a modelAttribute in Spring MVC <form:form> tag>

    Hi all,

    Using 3.0.0.RELEASE, SWF 2.0.8.RELEASE

    Bottom line up front: how do I reference objects from various SWF scopes as a modelAttribute in a Spring <form:form>?


    I have a simple web flow that uses a <var/> to create a domain object in flowScope:

    From flow definition xml:

    Code:
    <var name="flowScope.users" class="com..Users"  />
    
    	<!-- A sample view state -->
    	<view-state id="view-state-1" model="flowScope.users" >
    		<transition on="save" to="saveUser"/>
    		<transition on="success" to="view-state-2" />
    		<transition on="cancel" to="end-state" />
    	</view-state>

    My views are apache tiles views using JSPX and Spring MVC <form:form> tags (this started life as a Roo app):

    Code:
    <form:form action="${form_url}" method="POST" ModelAttribute="flowScope.users">
    ....
    </form:form>
    Everything works great if I do not declare the <var> I am using as a modelAttribute for the <form:form> into a specific SWF namespace (i.e. 'users'[works] vs. 'FlowScope.users'[does not work]), but as soon as declare the <var> as flowScope.users I have problems.

    If I do this (thinking that SWF scope resolution rules will apply):

    Code:
    <form:form action="${form_url}" method="POST" modelAttribute="users">
    I get the following runtime error when hitting the flow:

    Code:
    Attempting to handle [org.springframework.webflow.execution.FlowExecutionException: Exception thrown in state 'view-state-1' of flow 'sampleflow'] with root cause [java.lang.IllegalStateException: 
    Neither BindingResult nor plain target object for bean name 'users' available as request attribute]
    Rethrowing unhandled flow execution exception
    Unlocking conversation
    If I try to be more specific and prefix the modelAttribute with a SWF namespace I get pretty much the same:

    <form:form action="${form_url}" method="POST" modelAttribute="flowScope.users">

    Yields the similarly vexing:

    Code:
    Attempting to handle [org.springframework.webflow.execution.FlowExecutionException: Exception thrown in state 'view-state-1' of flow 'sampleflow'] with root cause [java.lang.IllegalStateException: 
    Neither BindingResult nor plain target object for bean name 'flowScope' available as request attribute]
    Rethrowing unhandled flow execution exception
    Unlocking conversation
    What am I missing? Shouldn't I be able to declare an object at flowScope and let the user "work on it" through various stages of the flow?

    Or do I have to copy the object to viewScope or flashScope every time and/or persist it at every step? (probably not)

    Bottom line, how do I reference objects from various SWF scopes as a modelAttribute in a Spring <form:form>?

    Thanks.

  2. #2
    Join Date
    Feb 2010
    Location
    United States
    Posts
    4

    Talking Solved

    Apparently declaring a var in the flow-config.xml doesn't instantiate it.

    I created a resource file with some beans and used:

    Code:
    <on-start>
    	<evaluate expression="beanFromResource" result="flowScope.users"></evaluate>
    </on-start>
    ..but it looks like you could use any expression that creates the right type of object.

    SWF rocks as advertised.

  3. #3
    Join Date
    Jun 2010
    Posts
    3

    Default Copying request parameters to flowscope

    Hi All,
    I am using the evaluate expression in the following manner to copy the request parameter in the spring webflow to flow scope.

    <evaluate expression="requestParameters.ondCityCodeMonth" result="flowScope.depMonth"></evaluate>

    In the above case the the request parameter name is ondCityCodeMonth. The below works properly.

    But my requirement is that the parameter name is ondCityCode[0].month. In this case the above expression is changed to

    <evaluate expression="requestParameters.ondCityCode[0].month" result="flowScope.depMonth"></evaluate>
    In this case the string requestParameters.ondCityCode[0].month is taken as an expression and it throws an error that the expression cannot be evaluated.

    Has anyone faced such problem. Please let me know how it can be fixed.

    Thanks in advance

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •