Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts 2 iteration with inputs

 
K Dombroski
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Jim, that does look like exactly what I need!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic