Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first thing here is to use well the indexed and logic:iterate tags to generate the code. If having doubts about this, check out this answer given by me, which explains in detail how to use indexed attributes in struts: <a href="https://stackoverflow.com/a/10247033/1251715">indexed and logic:iterate</a></p> <p>Then, you have to consider the scenario where an user wants to add or delete rows, and update indexes correctly so struts will be able to retrieve data as you submit the form. I encountered this problem once and what I did was:</p> <p> <li><strong>on add</strong>: using javascript, find out what is the last line of the table and, by looking at the generated code of the page, generate a new table row with empty contents, the index inside the square brackets. Finally, add to table <br></p> <p>EXAMPLE:</p> <p>a table:</p> <pre><code>&lt;table&gt;&lt;tr&gt;&lt;td name='whatever[0].something'&gt;asdf&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td name='whatever[1].something'&gt;asdf&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td name='whatever[2].something'&gt;asdf&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; </code></pre> <p>to add a row, create it in javascript like this:</p> <pre><code>var newRow = '&lt;tr&gt;&lt;td name='whatever[3].something'&gt;asdf&lt;/td&gt;&lt;/tr&gt; </code></pre> <p>and append it to the table.</p> <p></li> <li><strong>on del</strong>:Using the same technique as above find out which line (or corresponding index) was deleted. Then, edit the indexes of the remaining rows so that it matches the order of elements for the subsequent rows.<br></p> <p>EXAMPLE:</p> <p>a table:</p> <pre><code>&lt;table&gt;&lt;tr&gt;&lt;td name='whatever[0].something'&gt;asdf0&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td name='whatever[1].something'&gt;asdf1&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td name='whatever[2].something'&gt;asdf2&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; </code></pre> <p>let's say you delete <strong>asdf1</strong> by removing it from the dom. then, the new table will look like this:</p> <pre><code>&lt;table&gt;&lt;tr&gt;&lt;td name='whatever[0].something'&gt;asdf0&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td name='whatever[2].something'&gt;asdf2&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; </code></pre> <p>now we have to update indexes so it matches the right order, by changing the name of the second td to have an index of <strong>1</strong>, that way, the table is back to a struts indexed format:</p> <pre><code>&lt;table&gt;&lt;tr&gt;&lt;td name='whatever[0].something'&gt;asdf0&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td name='whatever[1].something'&gt;asdf2&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; </code></pre> <p></li> </p> <p>I hope it's clear enough. I obviously can't write all the js functions, since they require some work, but with this information you can make it on your own.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload