You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by KE LI <hk...@gmail.com> on 2009/01/19 16:47:09 UTC
Dynamic TextFields in Struts 2
Dear All, I want to do something like this:
in my action i create:
List<String> textFields = new ArrayList<String>();
and i tried to write set method in 2 ways:
1. public void setTextFields (List<String> textFields)
2. public void setTextFields(String text)
{
textFields.add(text);
}
and in my jsp, i want to get something like this:
<s:iterator ...>
<s:textfield name="textFields[%{#status.index}]"/>
</s:iterator>
But I found that for both setter methods, there are errors:
com.opensymphony.xwork2.util.OgnlValueStack - Caught an exception while
evaluating expression 'test_string[0]' against value stack
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
Can anyone help me on how to create such a dynamic textFields (Considering
action implementation)? Thanks in advance!
--
Best Regards,
Licco
Re: Dynamic TextFields in Struts 2
Posted by KE LI <hk...@gmail.com>.
Hi Dave and Shashi,
Thanks for you two's quick reply!! It does help~:) I just got up, lol.
Licco
2009/1/20 sasikumar <sa...@deciphar.com>
> Hi,
> you dont have to explicitly add the values to the list in the setter
> methods, since the framework will do that for you ,
> also you dont have to explicitly provide the index in the property field
> (name) (even though it will work with explicit indexing as well) . refer the
> fallowing code for help , make sure you have the getters and setters
> created in your model or action respectively.
>
> <s:iterator value="trainingSessionDetails"
> id="trainingSessionDetailsL" status="status">
> <td><s:textfield name="trainingSessionName"
> id="sessionNameL"
> value="%{#trainingSessionDetailsL.sessionName}"
> size="8"></s:textfield></td>
> <td><s:textarea name="trainingSessionDescription"
> id="sessionDescriptionL"
>
> value="%{#trainingSessionDetailsL.sessionDescription}" /></td>
> <td><s:textfield name="trainingSessionStartDate"
> id="sessionStartDateL%{#status.index}"
> value="%{#trainingSessionDetailsL.sessionStartDate}"
> size="16" /></td>
> <td><s:textfield name="trainingSessionEndDate"
> id="sessionEndDateL%{#status.index}"
> value="%{#trainingSessionDetailsL.sessionEndDate}"
> size="16" /></td>
> </tr>
> </s:iterator>
>
> Shashi
>
>
> Dear All, I want to do something like this:
>> in my action i create:
>> List<String> textFields = new ArrayList<String>();
>> and i tried to write set method in 2 ways:
>> 1. public void setTextFields (List<String> textFields)
>> 2. public void setTextFields(String text)
>> {
>> textFields.add(text);
>> }
>>
>> and in my jsp, i want to get something like this:
>> <s:iterator ...>
>> <s:textfield name="textFields[%{#status.index}]"/>
>> </s:iterator>
>>
>> But I found that for both setter methods, there are errors:
>> com.opensymphony.xwork2.util.OgnlValueStack - Caught an exception while
>> evaluating expression 'test_string[0]' against value stack
>> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
>> at java.util.ArrayList.RangeCheck(ArrayList.java:547)
>>
>> Can anyone help me on how to create such a dynamic textFields
>> (Considering
>> action implementation)? Thanks in advance!
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Best Regards,
Licco
Re: Dynamic TextFields in Struts 2
Posted by sasikumar <sa...@deciphar.com>.
Hi,
you dont have to explicitly add the values to the list in the
setter methods, since the framework will do that for you ,
also you dont have to explicitly provide the index in the property field
(name) (even though it will work with explicit indexing as well) . refer
the fallowing code for help , make sure you have the getters and
setters created in your model or action respectively.
<s:iterator value="trainingSessionDetails"
id="trainingSessionDetailsL" status="status">
<td><s:textfield name="trainingSessionName"
id="sessionNameL"
value="%{#trainingSessionDetailsL.sessionName}"
size="8"></s:textfield></td>
<td><s:textarea name="trainingSessionDescription"
id="sessionDescriptionL"
value="%{#trainingSessionDetailsL.sessionDescription}" /></td>
<td><s:textfield name="trainingSessionStartDate"
id="sessionStartDateL%{#status.index}"
value="%{#trainingSessionDetailsL.sessionStartDate}" size="16" /></td>
<td><s:textfield name="trainingSessionEndDate"
id="sessionEndDateL%{#status.index}"
value="%{#trainingSessionDetailsL.sessionEndDate}" size="16" /></td>
</tr>
</s:iterator>
Shashi
> Dear All, I want to do something like this:
> in my action i create:
> List<String> textFields = new ArrayList<String>();
> and i tried to write set method in 2 ways:
> 1. public void setTextFields (List<String> textFields)
> 2. public void setTextFields(String text)
> {
> textFields.add(text);
> }
>
> and in my jsp, i want to get something like this:
> <s:iterator ...>
> <s:textfield name="textFields[%{#status.index}]"/>
> </s:iterator>
>
> But I found that for both setter methods, there are errors:
> com.opensymphony.xwork2.util.OgnlValueStack - Caught an exception while
> evaluating expression 'test_string[0]' against value stack
> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
> at java.util.ArrayList.RangeCheck(ArrayList.java:547)
>
> Can anyone help me on how to create such a dynamic textFields (Considering
> action implementation)? Thanks in advance!
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Dynamic TextFields in Struts 2
Posted by Dave Newton <ne...@yahoo.com>.
KE LI wrote:
> Dear All, I want to do something like this:
> in my action i create:
> List<String> textFields = new ArrayList<String>();
> and i tried to write set method in 2 ways:
> 1. public void setTextFields (List<String> textFields)
> 2. public void setTextFields(String text)
Without a machine to check with, I'd first make sure I (a) have a
getter, and (b) if on the initial form display I'm displaying any text
fields that there are backing list entries.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org