You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Minerva CC <mi...@yahoo.com> on 2007/04/11 21:00:52 UTC

[S2] Iterator and Index

Hi,
 
I want to generate indexed html elements via iterator. In Struts 1, I would do it as follows:
 
<logic:iterate name="namesForm" property="names" id="name">
    <html:text name="name" property="firstname" indexed="true" size="30"/>
    <html:text name="name" property="lastname" indexed="true" size="30"/>
</logic:iterate>
 
Then Struts 1 will generate the output like this:
 
<input type="text" name="name[0].firstname" size="30" value="">
<input type="text" name="name[0].lastname" size="30" value="">
 
<input type="text" name="name[1].firstname" size="30" value="">
<input type="text" name="name[1].lastname" size="30" value="">
... 
 
 
Now,  how can I do the same with Struts 2? I tried <s:iterator> and <s:textfield>. But, they don't have have equivalent attributes. Is there anyone who has an idea how to do it?
 
Thanks,
Willa


       
____________________________________________________________________________________
We won't tell. Get more on shows you hate to love 
(and love to hate): Yahoo! TV's Guilty Pleasures list.
http://tv.yahoo.com/collections/265 

Re: [S2] Iterator and Index

Posted by Laurie Harper <la...@holoweb.net>.
Minerva CC wrote:
> Hi,
>  
> I want to generate indexed html elements via iterator. In Struts 1, I would do it as follows:
>  
> <logic:iterate name="namesForm" property="names" id="name">
>     <html:text name="name" property="firstname" indexed="true" size="30"/>
>     <html:text name="name" property="lastname" indexed="true" size="30"/>
> </logic:iterate>
>  
> Then Struts 1 will generate the output like this:
>  
> <input type="text" name="name[0].firstname" size="30" value="">
> <input type="text" name="name[0].lastname" size="30" value="">
>  
> <input type="text" name="name[1].firstname" size="30" value="">
> <input type="text" name="name[1].lastname" size="30" value="">
> .... 
>  
>  
> Now,  how can I do the same with Struts 2? I tried <s:iterator> and <s:textfield>. But, they don't have have equivalent attributes. Is there anyone who has an idea how to do it?

What did you try? s:iterator and s:textfield seem like the right pair of 
tags to use. I think Struts 2 will take care of the property indexing 
for you automatically (could be wrong on that though).

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Iterator and Index

Posted by Laurie Harper <la...@holoweb.net>.
Dave Newton wrote:
> --- bradharris <bm...@gmail.com> wrote:
>> Any Response to this question?  I'm really hoping this wasn't left out of
>> Struts2, but I can't seem to find anything indicating there is support for
>> iterative form fields.  This is a pretty big piece to be missing, so
>> feedback on the correct approach here would be appreciated.
> 
> There is [currently] no automagic support for indexed form fields.
> Constructing the names, however, is pretty straight-forward. It's not really
> that "big of a piece" IMO, but it is a minor irritation. File a JIRA if
> you're concerned (I don't know if there is one already).

To be clear, the part that is missing is automatically generating the 
names of the input fields appropriately. You can certainly still use 
collection-backed form fields, you just need a little extra coding in 
your JSP. Something like this:

     <s:textfield id="name[%{#stat.index}]" name="firstname" label="...">

or

     <s:textfield name="names[%{#stat.index}].firstname" label="...">

(I'm not sure off the top of my head which is right, but it'll be 
something along those lines...)

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Iterator and Index

Posted by Dave Newton <ne...@yahoo.com>.
--- bradharris <bm...@gmail.com> wrote:
> Any Response to this question?  I'm really hoping this wasn't left out of
> Struts2, but I can't seem to find anything indicating there is support for
> iterative form fields.  This is a pretty big piece to be missing, so
> feedback on the correct approach here would be appreciated.

There is [currently] no automagic support for indexed form fields.
Constructing the names, however, is pretty straight-forward. It's not really
that "big of a piece" IMO, but it is a minor irritation. File a JIRA if
you're concerned (I don't know if there is one already).

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Iterator and Index

Posted by bradharris <bm...@gmail.com>.
Any Response to this question?  I'm really hoping this wasn't left out of
Struts2, but I can't seem to find anything indicating there is support for
iterative form fields.  This is a pretty big piece to be missing, so
feedback on the correct approach here would be appreciated.

-- 
View this message in context: http://www.nabble.com/-S2--Iterator-and-Index-tp9946320p15171908.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org