You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Zoran Avtarovski <zo...@sparecreative.com> on 2012/11/01 15:47:26 UTC
Multi dimension array from form
I have a two dimension array in my action:
Integer[][] dataArray with appropriate getter/setter.
In my form I use the following checkbox tag to pass the data from user to
action
<s:iterator var="attributeType" value="someList"
status="typeStat">
<s:iterator value="aDpendentList"
var="attribute" status="attStat">
<s:checkbox
name="dataArray[%{#typeStat.index}][%{#attStat.index}]"
label="%{#attribute.name}" fieldValue="%{#attribute.attributeId}"/>
</s:iterator>
</s:iterator>
The form renders correctly in that the checkboxes are named dataArray[0][1]
and so forth, but I can't the array form data into the array.
Is there something I'm missing? I thought this was possible.
I'd appreciate any help as the only other option I can see is to construct a
string with a the multi dimension data and then token and construct the
array in the action, which I'd rather not.
Z.
Re: Multi dimension array from form
Posted by Zoran Avtarovski <zo...@sparecreative.com>.
Thanks Jeffrey,
In the end I went with using a string representation of the array
'[firstIndex][secondIndex][value]' and then used a tokenizer to recreate
the array.
It was pretty straight forward in the end.
I don't know why but I thought I'd used multi dimensional arrays like that
in the past but when I went back to look at some past projects, we hadn't.
I think I was suffering a little delirium.
Z.
On 2/11/12 1:28 PM, "Jeffrey Black" <je...@yahoo.com> wrote:
>Z,
>
>Have a look at the following page:
>
>http://struts.apache.org/2.x/docs/html-form-buttons-howto.html
>
>I haven't worked through your use-case yet, but it may get you where you
>want to be. I've used these techniques in my apps.
>
>Best,
>
>jb
>
>
>On Nov 1, 2012, at 9:47 AM, Zoran Avtarovski <zo...@sparecreative.com>
>wrote:
>
>> I have a two dimension array in my action:
>>
>> Integer[][] dataArray with appropriate getter/setter.
>>
>> In my form I use the following checkbox tag to pass the data from user
>>to
>> action
>>
>> <s:iterator var="attributeType" value="someList"
>> status="typeStat">
>> <s:iterator value="aDpendentList"
>> var="attribute" status="attStat">
>> <s:checkbox
>> name="dataArray[%{#typeStat.index}][%{#attStat.index}]"
>> label="%{#attribute.name}" fieldValue="%{#attribute.attributeId}"/>
>> </s:iterator>
>> </s:iterator>
>>
>> The form renders correctly in that the checkboxes are named
>>dataArray[0][1]
>> and so forth, but I can't the array form data into the array.
>>
>> Is there something I'm missing? I thought this was possible.
>>
>> I'd appreciate any help as the only other option I can see is to
>>construct a
>> string with a the multi dimension data and then token and construct the
>> array in the action, which I'd rather not.
>>
>> Z.
>>
>>
>>
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Multi dimension array from form
Posted by Jeffrey Black <je...@yahoo.com>.
Z,
Have a look at the following page:
http://struts.apache.org/2.x/docs/html-form-buttons-howto.html
I haven't worked through your use-case yet, but it may get you where you want to be. I've used these techniques in my apps.
Best,
jb
On Nov 1, 2012, at 9:47 AM, Zoran Avtarovski <zo...@sparecreative.com> wrote:
> I have a two dimension array in my action:
>
> Integer[][] dataArray with appropriate getter/setter.
>
> In my form I use the following checkbox tag to pass the data from user to
> action
>
> <s:iterator var="attributeType" value="someList"
> status="typeStat">
> <s:iterator value="aDpendentList"
> var="attribute" status="attStat">
> <s:checkbox
> name="dataArray[%{#typeStat.index}][%{#attStat.index}]"
> label="%{#attribute.name}" fieldValue="%{#attribute.attributeId}"/>
> </s:iterator>
> </s:iterator>
>
> The form renders correctly in that the checkboxes are named dataArray[0][1]
> and so forth, but I can't the array form data into the array.
>
> Is there something I'm missing? I thought this was possible.
>
> I'd appreciate any help as the only other option I can see is to construct a
> string with a the multi dimension data and then token and construct the
> array in the action, which I'd rather not.
>
> Z.
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org