Results 1 to 4 of 4

Thread: SimpleFormController keeps on returning to sucessView!

  1. #1
    Join Date
    May 2006
    Location
    Paris, France
    Posts
    39

    Default SimpleFormController keeps on returning to sucessView!

    Hi guys. I'm sure I'm doing something really dumb, but the solution isn't obvious to me.

    My problem is that I have a simple portlet with a PortletModeHandlerMapping that maps the view mode to one Controller, and the edit view to a SimpleFormController.

    When I first enter the page, I get the view handler ok, and when I first enter the edit mode I get the formView of the SimpleFormController. After entering data and submitting it, I get the successView. I use the portal's controls to return to the view mode.

    The problem is that if I now return to the edit view, I'm presented with the successView! Of course, I want the formView, so that I can enter a second set of data.


    Here's my context file (there's some other data in another context file, but I think everything relevant is here):

    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "../../dtd/spring-beans.dtd">
    <beans>
    	<bean id="postItFrontPageController" class="org.gibby.sample.portlets.messaging.web.PostItFrontPageController">
            <property name="postManager">
                <ref bean="postManager"/>
            </property>	
    	</bean>
    	
    	<bean id="postItPostController" class="org.gibby.sample.portlets.messaging.web.PostItPostController">
    	    <property name="sessionForm"><value>true</value></property>
            <property name="commandName"><value>post</value></property>
            <property name="commandClass"><value>org.gibby.sample.portlets.messaging.bus.Post</value></property>
            <property name="formView"><value>postItForm</value></property>
            <property name="successView"><value>postItSuccess</value></property>
            <property name="postManager">
                <ref bean="postManager"/>
            </property>
         </bean>
    	<!-- Handler Mapping -->
    
    	<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
    		<property name="order" value="20"/>
    		<property name="portletModeMap">
    			<map>
    				<entry key="view"><ref bean="postItFrontPageController"/></entry>
    				<entry key="edit"><ref bean="postItPostController"/></entry>
    			</map>
    		</property>
    	</bean>
    </beans>
    Thanks for your help!

    David

  2. #2
    Join Date
    Sep 2004
    Location
    Arizona, USA
    Posts
    383

    Default

    The JSR 168 spec requires that renderParameters be preserved when using the portal controls to change window state or portlet mode. That can sometimes lead to unexpected behaviors when the render parameters from one mode are also used in another. What is happening in your case is that SimpleFormController uses renderParameters to indicate that the form was submitted and whether it was a successful submit. When you switch to view mode and then back to edit mode, those renderParameters are still in effect and so the controller is still showing the successView.

    There are a couple ways you might tackle this issue:

    You can override the setFormSubmit / isFormSubmission and setInvalidSubmit / isInvalidSubmission methods to use something other than a render parameter. This will lets you have more control over something you could clear during view mode.

    Instead of using the successView, you could change the renderParameters after a successful submission to display a different view in edit mode, or even just show the initial form again, perhaps with a message that the change was successful.

    Hope that helps!

  3. #3
    Join Date
    Sep 2004
    Location
    Arizona, USA
    Posts
    383

    Default

    One other thought that I have seen applied nicely is that after a successful submit, you could go ahead and change the mode back to 'view' automatically.

  4. #4
    Join Date
    May 2006
    Location
    Paris, France
    Posts
    39

    Default

    Thanks for your help, John! I'll let you know as soon as I give it a try.

    David

Posting Permissions

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