Results 1 to 5 of 5

Thread: Direct call onSubmit in SimpleFormController

  1. #1
    Join Date
    May 2007
    Posts
    3

    Default Direct call onSubmit in SimpleFormController

    Hello everyone,
    I'm using SimpleFormController to implement a search function. In which the formBackingObject() get search parameters from the request, perform a search, and returns "searchResult" to form display. In the form, there are some submit buttons such as "sort by name", "sort by date", etc. while onSubmit() gets the button's name to process sort function (a search infact) and returns "searchResult" in the same view so that a user can go on sorting in another way.
    The full process should like this:
    Code:
                       searchResult          searchResult          
    formBackingObject ----return----> form  ----submit----> onSubmit
                                        ^                       |
                                        |                       |
                                         <-------return---------- 
                                              searchResult
    It runs perfect for the first submition, as the following sequence:
    formBakingObject->form->onSubmit->form
    but if user continue to submit, the formBackingObject() is called again, in this case, the original search parameters are lost. so, the qustion is how I can "bypass" the formBackingObject(), and submit data form directely to onSubmit() fuction?

    ps:
    - I've set setSessionForm(true) in formBackingObject()
    - I've set method="POST" for the form
    - The command calss for SimpleFormController is set to SearchResult


    Thanks a lot.
    Last edited by ren78min; Aug 30th, 2009 at 06:40 AM.

  2. #2
    Join Date
    May 2007
    Posts
    3

    Default

    I've just tryed an approch with AbstractCommandController, I think it is less complecate.
    The question comes to "how to keep data between a sequence of submitions."
    A solution is to keep each of them with a <form:hidden> tag, but when the data object becomes complecated this solution seems impossible.
    I imagin that there should be a simple way to do this, but I didn't find.
    Someone can help? Thanks.

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Simply set the sessionForm to true. Your object is stored into the session and formBackingObject is called only once... (I suggest the web chapter in the reference guide...).

    - I've set setSessionForm(true) in formBackingObject()
    You must set it in the constructor or your xml configuration... in the formBackingObject it is set to late.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  4. #4
    Join Date
    May 2007
    Posts
    3

    Default

    Thank you for your attention.

    I tryed to set sessionForm in the xml:
    Code:
    	<bean id="searchController" class="com.mren.controller.SearchCtrl">
    		<property name="sessionForm"><value>true</value></property>
    ......
    		<property name="commandClass" 	value="com.mren.datacargo.SearchResult"/>
    		<property name="commandName" value="searchResult"/>
    	</bean>
    but nothing changes.
    I put some code to print the data in jsp, it shows the searchResult exist only in request scope
    Code:
    ......
    <body>
    session:<c:out value="${sessionScope.searchResult.totalObjectsCount}"></c:out>
    request:<c:out value="${searchResult.totalObjectsCount}"></c:out>
    <form:form action="/search.htm" commandName="searchResult" method="POST">
    ......
    I tried to put data into session manualy by adding
    Code:
    WebUtils.setSessionAttribute(request, "searchResult", searchResult);
    to onSubmit(), but formBackingObject() is always called.

    the actual sequence is:
    request -> formBackingObject() -> form -> onSubmit() -> form -> formBackingObject() -> onSubmit() -> form -> formBackingObject() -> onSubmit() -> form ...

    while the one expected is :
    request -> formBackingObject() -> form -> onSubmit() -> form -> onSubmit() -> form -> onSubmit() -> form ...

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    The bean in sessionscope has a different, generated name so checking if it exists doesn't work that way.

    If you set session form to true you should be getting the expected behavior. If you don't there is either a programming or configuration mistake on your side...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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