Results 1 to 3 of 3

Thread: Binding data from the view to the Form Backing Object

  1. #1
    Join Date
    Mar 2011
    Posts
    7

    Default Binding data from the view to the Form Backing Object

    Hello all,


    I have the following jsp page that populates a table and inserts a radio button (one per row). Upon form submission the value of the selected radio button, which represents an index, is correctly passed to the form baking object, everything works just fine. Here is the jsp:


    Code:
    <table width="1000" bgcolor="f8f8ff" border="2" cellspacing="0" cellpadding="5" align ="center">  
     <form:form method="post" commandName="scriptFill">   
       <tr>
          
          <td align="center" width="30%">Filename</td>
          <td align="center" width="30%">Description</i></td>
          <td align="center" width="30%">Name</td>
          <td align="center" width="10%">Select</td>
       </tr>
      
      
      
      <c:forEach items="${myList}" var="script">
       <tr>
          <td align="left" width="30%"><c:out value="${script.fileName}"/></td>
          <td align="left" width="30%"><i><c:out value="${script.description}"/></i></td>
          <td align="left" width="30%"><i><c:out value="${script.name}"/></i></td>
          <td align="center" width="10%"><form:radiobutton path="index" value="${script.index}" label="" ></form:radiobutton></td>  
       </tr>
      </c:forEach> 
      
      </table>
      <center>
      <i><input type="submit" align="center" value="Populate" ></i>
      </center>
     </form:form>
    What I want to do is eliminate both the radio button and the submit button at bottom of the page, and have one submit button per row. This way the user will only need one click to pass the value of the index to the form backing object. Here is more code with comments for clarity:

    Code:
    <table width="1000" bgcolor="f8f8ff" border="2" cellspacing="0" cellpadding="5" align ="center"> 
     <form:form method="post" commandName="scriptFill">   
       <tr>
          
          <td align="center" width="30%">Filename</td>
          <td align="center" width="30%">Description</i></td>
          <td align="center" width="30%">Name</td>
          <td align="center" width="10%">Select</td>
       </tr>
      
      
      
      <c:forEach items="${myList}" var="script">
       <tr>
          <td align="left" width="30%"><c:out value="${script.fileName}"/></td>
          <td align="left" width="30%"><i><c:out value="${script.description}"/></i></td>
          <td align="left" width="30%"><i><c:out value="${script.name}"/></i></td>
    
           <%-- ELIMINATE THE RADIO BUTTON
          <td align="center" width="10%"><form:radiobutton path="index" value="${script.index}" label="" ></form:radiobutton></td>  
          	--%>
          	   
          	<%-- HAVE A SUBMIT BUTTON THAT PASSES THE RIGHT VALUE OF script.index TO THE INDEX VALUE OF THE FORM BACKING OBJECT
          	<td align="center" width="10%> <input type="submit" align="center"  value="Goto" ></i> </td>
            --%>
          	   
          </td>
          
          
          
         
      </c:forEach> 
      
      </table>
      <center>
                     <%-- ELIMINATE THIS SUBMIT BUTTON <i><input type="submit" align="center" value="Populate" ></i>    --%>
      </center>
     </form:form>

    I'm also including images to make things more clear. I want to go from this:

    Screen shot-1.jpg


    to this:

    Screen shot-2.jpg



    Please let me know if you have further questions, I might not have been clear.

    Thank you in advance!
    Last edited by rufu; Sep 3rd, 2011 at 06:45 AM.

  2. #2
    Join Date
    Mar 2011
    Location
    Washington, DC
    Posts
    60

    Default

    How about this?
    Code:
    <input type="submit" align="center" value="Populate_${script.index}" >
    when you receive at your server side, you will parse this value and try to get the index number.

    Lets me know if this works for you.

  3. #3
    Join Date
    Mar 2011
    Posts
    7

    Default

    Hi p782,

    thanks for the reply but unfortunately it still does not work!
    If I try with your code I get submit buttons with "Populate_${script.index}" on them but with not the correct behavior. The value of the index does not get passed to the controller via the form backing object, it always stays at the default value.

    Any more ideas?

    Thanks!!

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
  •