You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ignacio de Córdoba <ic...@skios.es> on 2009/07/13 00:16:02 UTC

s:checkbox inside a s:iterator and values in a Integer[]

Hello,
I've browsed nabble, google, ... but can't find a simple example on how to
do something very simple.

I need to iterate through, let's say, a picture category list, showing each
category as a s:checkbox. The picture belongs to some of these categories
(and user can changed that, or course, thanks to the checkboxes), so some of
the checkboxes must be pre-checked. Which of them are checked is shown in a
Integer[] (could be String[] if necesary, no problem). I guessed the right
way to do it is using a String or Integer array as checked values will be
sent to the struts2 action through that same property.
Is it that difficult to use s:checkbox for this? I know how to do it using
s:checkboxlist but can't here as I need special format in the iteration.

For some reason the following:
<s:iterator value="categoryTree">
<s:checkbox labelposition="right" name="categoryId" fieldValue="%{id}"
label="%{name}"/>
</s:iterator>

(categoryId is a Integer[] having which id values should be checked but all
checkboxes appear as checked)

For some reason I've found more people with this same problem but they got
no answers. Thanks for any example or ideas if I must change the way
pre-checked data is got from the action.
Ignacio
-- 
View this message in context: http://www.nabble.com/s%3Acheckbox-inside-a-s%3Aiterator-and-values-in-a-Integer---tp24452969p24452969.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: s:checkbox inside a s:iterator and values in a Integer[]

Posted by Ignacio de Córdoba <ic...@skios.es>.
Thanks a lot for reply. It works OK that way. I had to make a getter for the
Category objects as a List and maintain the setter for the categoryId
Integer array. It would be great if s:checkbox could also check when to
pre-check the checkbox in the same way as s:checkboxlist does (I think I
used s:checkboxlist getting checked fields from the Integer[] id getter. It
makes sense to use the same property to get checkbox status and to set
checkbox status)

Anyway, thanks a lot for your example.
Ignacio


Musachy Barroso wrote:
> 
> you need to specify the "value" attribute, which is the one that will
> make it checked or not, for example, assume "possibleValues" is the
> list of possible values, and "selectedValues" is the list of currently
> selected values, and both lists contain objects that have an int "id"
> field (same type of objects):
> 
> <s:iterator value="%{possibleValues}">
> <s:checkbox name="categoryId" fieldValue="%{id}"
> value="%{#selectedValues.contains(top)}" />
> </s:iterator>
> 
> musachy
> 
> 2009/7/12 Ignacio de Córdoba <ic...@skios.es>:
>>
>> Hello,
>> I've browsed nabble, google, ... but can't find a simple example on how
>> to
>> do something very simple.
>>
>> I need to iterate through, let's say, a picture category list, showing
>> each
>> category as a s:checkbox. The picture belongs to some of these categories
>> (and user can changed that, or course, thanks to the checkboxes), so some
>> of
>> the checkboxes must be pre-checked. Which of them are checked is shown in
>> a
>> Integer[] (could be String[] if necesary, no problem). I guessed the
>> right
>> way to do it is using a String or Integer array as checked values will be
>> sent to the struts2 action through that same property.
>> Is it that difficult to use s:checkbox for this? I know how to do it
>> using
>> s:checkboxlist but can't here as I need special format in the iteration.
>>
>> For some reason the following:
>> <s:iterator value="categoryTree">
>> <s:checkbox labelposition="right" name="categoryId" fieldValue="%{id}"
>> label="%{name}"/>
>> </s:iterator>
>>
>> (categoryId is a Integer[] having which id values should be checked but
>> all
>> checkboxes appear as checked)
>>
>> For some reason I've found more people with this same problem but they
>> got
>> no answers. Thanks for any example or ideas if I must change the way
>> pre-checked data is got from the action.
>> Ignacio
>> --
>> View this message in context:
>> http://www.nabble.com/s%3Acheckbox-inside-a-s%3Aiterator-and-values-in-a-Integer---tp24452969p24452969.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
>>
>>
> 
> 
> 
> -- 
> "Hey you! Would you help me to carry the stone?" Pink Floyd
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/s%3Acheckbox-inside-a-s%3Aiterator-and-values-in-a-Integer---tp24452969p24453782.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: s:checkbox inside a s:iterator and values in a Integer[]

Posted by Musachy Barroso <mu...@gmail.com>.
you need to specify the "value" attribute, which is the one that will
make it checked or not, for example, assume "possibleValues" is the
list of possible values, and "selectedValues" is the list of currently
selected values, and both lists contain objects that have an int "id"
field (same type of objects):

<s:iterator value="%{possibleValues}">
<s:checkbox name="categoryId" fieldValue="%{id}"
value="%{#selectedValues.contains(top)}" />
</s:iterator>

musachy

2009/7/12 Ignacio de Córdoba <ic...@skios.es>:
>
> Hello,
> I've browsed nabble, google, ... but can't find a simple example on how to
> do something very simple.
>
> I need to iterate through, let's say, a picture category list, showing each
> category as a s:checkbox. The picture belongs to some of these categories
> (and user can changed that, or course, thanks to the checkboxes), so some of
> the checkboxes must be pre-checked. Which of them are checked is shown in a
> Integer[] (could be String[] if necesary, no problem). I guessed the right
> way to do it is using a String or Integer array as checked values will be
> sent to the struts2 action through that same property.
> Is it that difficult to use s:checkbox for this? I know how to do it using
> s:checkboxlist but can't here as I need special format in the iteration.
>
> For some reason the following:
> <s:iterator value="categoryTree">
> <s:checkbox labelposition="right" name="categoryId" fieldValue="%{id}"
> label="%{name}"/>
> </s:iterator>
>
> (categoryId is a Integer[] having which id values should be checked but all
> checkboxes appear as checked)
>
> For some reason I've found more people with this same problem but they got
> no answers. Thanks for any example or ideas if I must change the way
> pre-checked data is got from the action.
> Ignacio
> --
> View this message in context: http://www.nabble.com/s%3Acheckbox-inside-a-s%3Aiterator-and-values-in-a-Integer---tp24452969p24452969.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
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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