You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Daniel Kern-Ekins <d....@bigfoot.com> on 2001/02/28 19:58:19 UTC

Checkbox in Table with unique values

I am confused how to architect in struts a form that has
multiple checkboxes where several can be checked and i need
to iterate through the results.

problem :
user has designed form [a table] with several columns that
identify an item(s) from a datasource and a checkbox column.

when the <xxxAction> receives the <xxxForm>, i need to
discover, if one or more of the checkbox's were checked,
iterate through each one checked.
on each iteration, need to determine which item it belongs
to and "map" the checkbox checked to the actual data from
the datasource.

partial solution:
have iterator produce table.
create pairs of named checkboxes and named "hidden" input
fields with the values set to the unique identifier in the
datasource.
<%! private int someiterator = 0; %>
     <input type="checkbox" name="cbx<%= someiterator %>"
     value=<struts:htmlProperty name="company"
property="someId" />>

     <input type=hidden
            name="cbxvalue<%= someiterator %>"
           value=<struts:htmlProperty name="dataBean"
property="dataBeanId" />
     >

but how do i get these values (cbx0, cbx1 and
cbxvalue0=<blah>, cbxvalue1=<blah>) back into <xxxForm>,
<xxxAction>?

this seems very un-struts-like. what would be the proper
solution in struts? i have currently developed in .05
version.

this looks *very* similar to a december 17 2000, "Checkbox
Issue" item in the archive but i don't see an answer.
thanks,
dan


Re: Checkbox in Table with unique values

Posted by Maya Muchnik <mm...@pumatech.com>.
Daniel,
I have only small suggestion for you, because I do not know yet how
struts can help with multiple checkboxes. You can use taglibs/input
library (project Taglibs). It includes Checkbox tag and an example for
multiple checkboxes.
Hope this help.
Maya

Daniel Kern-Ekins wrote:

> I am confused how to architect in struts a form that has
> multiple checkboxes where several can be checked and i need
> to iterate through the results.
>
> problem :
> user has designed form [a table] with several columns that
> identify an item(s) from a datasource and a checkbox column.
>
> when the <xxxAction> receives the <xxxForm>, i need to
> discover, if one or more of the checkbox's were checked,
> iterate through each one checked.
> on each iteration, need to determine which item it belongs
> to and "map" the checkbox checked to the actual data from
> the datasource.
>
> partial solution:
> have iterator produce table.
> create pairs of named checkboxes and named "hidden" input
> fields with the values set to the unique identifier in the
> datasource.
> <%! private int someiterator = 0; %>
>      <input type="checkbox" name="cbx<%= someiterator %>"
>      value=<struts:htmlProperty name="company"
> property="someId" />>
>
>      <input type=hidden
>             name="cbxvalue<%= someiterator %>"
>            value=<struts:htmlProperty name="dataBean"
> property="dataBeanId" />
>      >
>
> but how do i get these values (cbx0, cbx1 and
> cbxvalue0=<blah>, cbxvalue1=<blah>) back into <xxxForm>,
> <xxxAction>?
>
> this seems very un-struts-like. what would be the proper
> solution in struts? i have currently developed in .05
> version.
>
> this looks *very* similar to a december 17 2000, "Checkbox
> Issue" item in the archive but i don't see an answer.
> thanks,
> dan