wood burning stoves 2.0*
The moose likes Struts and the fly likes struts 2 iteration with inputs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts 2 iteration with inputs" Watch "struts 2 iteration with inputs" New topic
Author

struts 2 iteration with inputs

K Dombroski
Ranch Hand

Joined: Dec 03, 2005
Posts: 39
I am wondering how to go about iterating over a table with inputs in struts 2. It appears that all the struts tags automatically create a new row for each input field, which totally messes up my table format. If I want to have a table with, say, 5 inputs in each row, how do I do that? I don't want struts 2 to put in the extra <tr> and <td> tags that it uses for labelling in this case.
Jim Hardin
Ranch Hand

Joined: Aug 02, 2006
Posts: 46
K,
If I understand your question, you should be able to accomplish what you want with Indexed Properties. Have a look at the section entitled "Dynamic Indexes for Indexed Properties" at:
Struts Indexed Properties Docs
-Jim
K Dombroski
Ranch Hand

Joined: Dec 03, 2005
Posts: 39
Thanks for your reply. I am familiar with indexed properties and have used them extensively in struts 1. However, struts 2 has those new UI tags, so when I put something in my jsp such as the following:
<table class="basic-table">
<tr><th>title</th><th>title2</th></tr>
<s:iterator value="accountRangeOptionsList" id="accountRangeOptionsList">
<tr>
<td>
<s:textfield name="elementPositionNumber"/>
</td>
<td>
<s:textfield name="firstNumberInRange"/>
</td>
</tr>
</s:iterator>
</table>
the html gets rendered as
<table class="basic-table">
<tr><th>title</th><th>title2</th></tr>

<tr>
<td>
<tr>
<td class="tdLabel"></td>
<td
><input type="text" name="elementPositionNumber" value="1" id="tableform_elementPositionNumber"/>
</td>
</tr>

</td>
<td>
<tr>
<td class="tdLabel"></td>
<td
><input type="text" name="firstNumberInRange" value="1" id="tableform_firstNumberInRange"/>
</td>
</tr>

</td>
</tr>

<tr>
<td>
<tr>
<td class="tdLabel"></td>
<td
><input type="text" name="elementPositionNumber" value="2" id="tableform_elementPositionNumber"/>
</td>
</tr>

</td>
<td>
<tr>
<td class="tdLabel"></td>
<td
><input type="text" name="firstNumberInRange" value="1" id="tableform_firstNumberInRange"/>
</td>
</tr>

</td>
</tr>


</table>
which really messes up my table (putting each input field on its own row, and all aligned vertically in the same column). Struts 2 does not have indexed properties from what I have been able to find, and I can't seem to find any examples or documentation anywhere on how to make a table like what I need in struts 2.

What I really want is to be able to use the tag without having it add the extra <tr> and <td> tags around it. I can see how it would often be useful, but I cannot imagine that they would force you to always lay things out that way. I would think that if it could be done in struts 1, they would not take that functionality away.
Jim Hardin
Ranch Hand

Joined: Aug 02, 2006
Posts: 46
K,
Yes, I was thinking Struts 1, but would be surprised if "Indexed Properties" were not supported in Struts 2. I tried dropping the
"struts2-showcase-2.0.6.war" in a local tomcat "webapps" folder, and was able (in that application) to navigate to
"Person Manager" > "List All People" > "Edit People"
which sounds like exactly what you're looking for. Maybe try having a look at that.
-Jim
[ April 09, 2007: Message edited by: Jim Hardin ]
K Dombroski
Ranch Hand

Joined: Dec 03, 2005
Posts: 39
Thanks, Jim, that does look like exactly what I need!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts 2 iteration with inputs
 
Similar Threads
How to add page break in table
Need an Idea
Mulitple fo:page-sequence
Fieldset alignment with tables
Help me to have a sortable table in my html profile!