4

I have the following jsp in which I have an option of adding and deleting rows of the table and in each row of the table which have the same fields I have to fill in the options and submit the form.

In the action class how do I retrieve the values of the row which I have filled in the JSP as there are more than one row that I fill in the table ?

This is my JSP:

<table id="fragmentTable" style="height: 100%; width: 100%">

    <tr class="tableRow" style='height: 5%;'>
      <td class='' style='position: absolute; left: 75%;'>
    <button value="Add Row" type="button" onclick="return addRow1();">Add Row</button>
    <button value="Delete Row" type="button" onclick="return deleteRow          ('dataTable')">Delete Row</button>
      </td>
    </tr>

     <tr>
    <td colspan="2"><br><br>
    <table id="dataTable" border="1" width=100% height=30% class='blueBorder'>
    <thead>
    <tr class='rowHeader'>
          <th width='14%'>Select</th>
          <th width='14%'>Opening Brace</th>
          <th width='14%'>Parameter</th>
          <th width='14%'>Relational Operator</th>
          <th width='14%'>Value</th>
          <th width='15%'>Closing Brace</th>
          <th width='15%'>Logical Operator</th>
    </tr>
    </thead>

    <tbody>


        <tr class='rowData' id=1>
<td>
<s:checkbox theme="simple" id="sel" name="GRF_FRAGID" value="false" /></td>
<td ><s:select headerKey="-1" headerValue="Select" list="#{'1':'(', '2':'((','3':'(((','4':'((((','5':'((((('}" name="GRF_OPNGBRCES" /></td>
<td>
<s:select label="Mode" headerKey="-1" headerValue="Select" list="#{'1':'=', '2':'!='}"
    name="GRF_OP" />
</td>
<td>
<s:textfield name="Country"/>
</td>

</tr>
</tbody>
</table>
Roman C
  • 49,761
  • 33
  • 66
  • 176
user2077648
  • 951
  • 7
  • 27
  • 42

1 Answers1

3

I don't understand exactly your page, but you need to use iterator (as suggested by @NidhishKrishnan ) and to point to the index through its IteratorStatus object:

<s:iterator value="yourlist" status="ctr" >
  <tr>
    <td><s:textfield name="yourlist[%{#ctr.index}].country"/></td>
  </tr>
 </s:iterator>

country should be written with first letter lowercase.

If you need to generate new rows with javascript, you must generate the same HTML that is "outputted" by the <s:textfield/> tag (click on View Source of your browser, and understand how it is generated).

This will create on the target Action (that must have the same List with a setter) a new List containing all the values from the page.

No need to act on one row singularly, you can update (for example) 10 rows in one post with this.


EDIT

Answering your comment, if you do not have any initial value, no iteration is involved: you can define the first row as the first element of the list, using the same syntax that you would use to add a new row.

There is no need to start from a List, the only requirement is to post list-formatted HTML elements to be set in the destination List.

Use this article as an example, to understand which javascript and HTML you need to create.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • How do I enter the iterator as initially the list is empty? – user2077648 Apr 19 '13 at 06:01
  • I have seen this link but I need to generate dropdowns, dont know how to do it using their javascript – user2077648 Apr 19 '13 at 10:15
  • As a hint, start with something really basic but that is working (one input field, add row, edit row, remove row, etc), only then add complexity. For the select, you can generate a select in javascript by using HTML ` – Andrea Ligios Apr 19 '13 at 10:20