You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bhaarat Sharma <bh...@gmail.com> on 2009/05/21 05:25:50 UTC
retrieving data from form that has unknown (changing) number of
fields
hi
I have a form that will have varying number of fields inside it. The number
of fields is generated dynamically and is not always the same. When I am
submitting this form to my action class, is there a way to get all the
fields back in a systematic manner? Does struts2 provide any mechanism to
do this? or am i Stuck with the good old fasioned way of naming my fields
with a prefix name and then keep looking for names in forloop untill they
run out.
Thanks!
Re: retrieving data from form that has unknown (changing) number of fields
Posted by Wes Wannemacher <we...@wantii.com>.
On Wednesday 20 May 2009 11:25:50 pm Bhaarat Sharma wrote:
> hi
>
> I have a form that will have varying number of fields inside it. The
> number of fields is generated dynamically and is not always the same. When
> I am submitting this form to my action class, is there a way to get all the
> fields back in a systematic manner? Does struts2 provide any mechanism to
> do this? or am i Stuck with the good old fasioned way of naming my fields
> with a prefix name and then keep looking for names in forloop untill they
> run out.
>
> Thanks!
Put the values in a collection of some sort, then just use indexed names.
For instance -
<s:textfield name="fieldName[0]" ... />
...
<s:textfield name="fieldName[n]" ... />
then in the page where you want to display the values -
<s:iterator value="fieldName" var="field">
<s:property value="field" />
</s:iterator>
-Wes
--
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org