Announcement Announcement Module
Collapse
No announcement yet.
What's the best way to move from one Form to another? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • What's the best way to move from one Form to another?

    Hi All,

    I'm a newbie for this spring framework. Currently using MVC & ORM part of this framework.

    I'm trying to develop a simple application and ran in to few issues.

    Question:

    I have :

    Form1 - Form2 - Form3.



    Form1 :

    - Get list of data using AbstractCommandController.
    - Has 2 submit buttons to open form view of Form2 & Form3

    Form2 :

    - Uses SimpleFormController

    - After user clicks "Form2" button in Form1, Form2 (FormView) gets displayed by overiding isFormSubmission method in SimpleFormController to return false by checking a request param from Form1.

    - After user fill this Form2, gets submitted and calls onSubmit() to save data.

    Form3 :

    - Uses SimpleFormController

    - After user clicks "Form3" button in Form1, Form3 (FormView) gets displayed by overiding isFormSubmission method in SimpleFormController to return false by checking a request param from Form1.

    - After user fill this Form3, gets submitted and calls onSubmit() to save data.

    I need user selected data & some hidden field data in Form1 needs to be captured in Form2 & 3 while showing formView.


    My issue is:

    After I bind some fields in command object of Form1 and try to obtain those fields Form2 & Form3. If the fieldValue comes from HTML input types, I could retrieve it. But if the field value is from hidden type, I couldn't get those values. In the below code snippet, I'm able to bind nameCommand.selectedLastName field, but not nameCommand.selectedFirstName. Do I need to use javaScript to populate this hidden field value?? Help me.

    1. what's the best way to move from Form1 to Form2/Form3 ?
    2. How to bind hidden fields?

    Code:
    <c&#58;forEach items="$&#123;currentNameList&#125;" var="nameDTO" varStatus="stsNameList">
    	<c&#58;choose>
    		<c&#58;when test="$&#123;nameCommand.selectedLastName == nameDTO.lastName&#125;">
    			 <spring&#58;bind path="nameCommand.selectedLastName">
    				<input type="radio" checked size="25" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;nameDTO.lastName&#125;"/>"/>
    			</spring&#58;bind>
    
    			<spring&#58;bind path="nameCommand.selectedFirstName"> 
    			<input name="$&#123;status.expression&#125;" value="<c&#58;out value="$&#123;nameDTO.firstName&#125;"/>" /> 
    			</spring&#58;bind> 
    
    		</c&#58;when>
    		<c&#58;otherwise>
    
    			<spring&#58;bind path="nameCommand.selectedLastName">
    			<input type="radio" size=25 name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;nameDTO.lastName&#125;"/>" />
    			</spring&#58;bind>
    
    			<spring&#58;bind path="nameCommand.selectedFirstName"> 
    			<input name="$&#123;status.expression&#125;" value="<c&#58;out value="$&#123;nameDTO.firstName&#125;"/>" /> 
    			</spring&#58;bind> 
    		</c&#58;otherwise>
    	</c&#58;choose>
    </c&#58;forEach>
    Thanks,
    VMR

  • #2
    Moving from one form to another can best be done by using the RedirectView. Since 1.1.2 (I believe) you can use forward: and redirect: prefixes in the view name to let Spring aumatically use a RedirectView.

    Have a look at the UrlBasedViewResolver to learn about those prefixes...

    About binding hidden fields, I don't really see any problems in your code there, but I also don't see hidden fields?

    Comment


    • #3
      Alef, Thanks for your reply. Forward & redirect helps.

      I corrected my code with hidden field and posted again.

      In the below code, selectedLastName field gets bound with java bean when I click on specific radio button. Issue is, binding selectedFirstName field.

      When I check nameCommand object in Controller, nameCommand java bean has the correct last name (selectedLastName) that I clicked in the form. But when I check the value of selectedFirstName, it has all 10 firstName values in that page.

      Is there anyway we can auto bind the selectedFirstName similar to selectedLastName?? (ie. hidden fields similar to radio button) I believe, since selectedLastName is a radio button, ServletRequestDataBinder knows which value to bind based on checked attribute of radio button. Since there's no such attribute of hidden elements, DataBinder object binds all listed values in selectedFirstName field of nameCommand. Is there any thing we can do with these hidden fields to get populated only with user selected values??

      Code:
      <c&#58;forEach items="$&#123;currentNameList&#125;" var="nameDTO" varStatus="stsNameList"> 
         <c&#58;choose> 
            <c&#58;when test="$&#123;nameCommand.selectedLastName == nameDTO.lastName&#125;"> 
                <spring&#58;bind path="nameCommand.selectedLastName"> 
                  <input type="radio" checked size="25" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;nameDTO.lastName&#125;"/>"/> 
               </spring&#58;bind> 
      
               <spring&#58;bind path="nameCommand.selectedFirstName"> 
               <input type=hidden name="$&#123;status.expression&#125;" value="<c&#58;out value="$&#123;nameDTO.firstName&#125;"/>" /> 
               </spring&#58;bind> 
      
            </c&#58;when> 
            <c&#58;otherwise> 
      
               <spring&#58;bind path="nameCommand.selectedLastName"> 
               <input type="radio" size=25 name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;nameDTO.lastName&#125;"/>" /> 
               </spring&#58;bind> 
      
               <spring&#58;bind path="nameCommand.selectedFirstName"> 
               <input type=hidden name="$&#123;status.expression&#125;" value="<c&#58;out value="$&#123;nameDTO.firstName&#125;"/>" /> 
               </spring&#58;bind> 
            </c&#58;otherwise> 
         </c&#58;choose> 
      </c&#58;forEach>
      VMR

      Comment

      Working...
      X