You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jyothrilinga Rao <jy...@gmail.com> on 2011/10/24 06:44:13 UTC

Edit a list of Strings to action

Hi,

I need to display a list of String objects and let the user edit them, when
the user submits the forms my List should be having the updated values.

*Action:
**private* List<String> inputStrings;
*

public* String execute() {
*if*(inputStrings==*null*){
 inputStrings = *new* ArrayList<String>();
 inputStrings.add("PQR");
 inputStrings.add("ABC");
}
*JSP:*
<s:iterator value=*"inputStrings"* status=*"sts"*>
    <s:textfield name=*"inputStrings[%{#sts.index}].value"* value=""></
s:textfield>
</s:iterator>
I can correctly display the list of Strings (in the inputStrings of action )
using the <s:property /> in the iterator body, but not able to figure out
what should be put in the value attribute to display and submit the action.
Could someone give me any pointers with the OGNL here.

Thanks,
JK.

PS: I am able to display and retrieved the edited values of list of domain
objects but not a list of String.

Re: Edit a list of Strings to action

Posted by Jyothrilinga Rao <jy...@gmail.com>.
Thank you.
there was no var attribute in iterator tag, but I could use id attribute
instead. Also had to make change to name to get is set on action.

I could get it work with either of the following.

<s:iterator value=*"inputStrings"* status=*"sts"* *id*="s">
  <s:textfield name="inputStrings[%{#sts.index}]" value="%{#s}"></
s:textfield>

or

<s:iterator value="inputStrings" status="sts" >
  <s:textfield name="inputStrings[%{#sts.index}]" value="%{top}"></
s:textfield>
Regards,
JK

On Mon, Oct 24, 2011 at 1:01 AM, Steven Yang <ke...@gmail.com> wrote:

> try
> <s:iterator value=*"inputStrings"* status=*"sts"* var="s">
>   <s:textfield name=*"inputStrings[%{#sts.index}].value"* value="%{#s}"></
> s:textfield>
>
> or
>
> <s:iterator value=*"inputStrings"* status=*"sts"*>
>   <s:textfield name=*"inputStrings[%{#sts.index}].value"* value="%{top}"></
> s:textfield>
>
> On Mon, Oct 24, 2011 at 2:21 PM, roger <ro...@googlemail.com>
> wrote:
>
> > <s:textfield="inputStrings[%{#sts.index}].value"
> > value="%{inputStrings[#sts.index].value}"
> >
> > --
> > View this message in context:
> >
> http://struts.1045723.n5.nabble.com/Edit-a-list-of-Strings-to-action-tp4931270p4931445.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
> >
> >
>

Re: Edit a list of Strings to action

Posted by Steven Yang <ke...@gmail.com>.
try
<s:iterator value=*"inputStrings"* status=*"sts"* var="s">
   <s:textfield name=*"inputStrings[%{#sts.index}].value"* value="%{#s}"></
s:textfield>

or

<s:iterator value=*"inputStrings"* status=*"sts"*>
   <s:textfield name=*"inputStrings[%{#sts.index}].value"* value="%{top}"></
s:textfield>

On Mon, Oct 24, 2011 at 2:21 PM, roger <ro...@googlemail.com> wrote:

> <s:textfield="inputStrings[%{#sts.index}].value"
> value="%{inputStrings[#sts.index].value}"
>
> --
> View this message in context:
> http://struts.1045723.n5.nabble.com/Edit-a-list-of-Strings-to-action-tp4931270p4931445.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
>
>

Re: Edit a list of Strings to action

Posted by roger <ro...@googlemail.com>.
<s:textfield="inputStrings[%{#sts.index}].value"
value="%{inputStrings[#sts.index].value}"

--
View this message in context: http://struts.1045723.n5.nabble.com/Edit-a-list-of-Strings-to-action-tp4931270p4931445.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