You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Toni Nehme <tn...@hotmail.com> on 2002/07/03 20:35:08 UTC

html:checkbox in a table

Hi Everyone,


Does anyone knows or have an example that displays a table of records with a 
checkbox in each row and when user submit the form,
will be able to know which row is checked?

If so,please let me know how to do it or send me an example.


Thanks.



_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: html:checkbox in a table

Posted by Andrew Hill <an...@gridnode.com>.
Haven't tried this with the struts taglib, but am making use of this concept
for my 'listviews' (where one can select multiple rows or records to do
stuff to - like delete)

With standard html a checkbox may have a value that it submitted when it is
ticked - and as the struts tags follow their html conterparts this should
hold true for them too.
(Nothing is submitted for an unticked checkbox - hence the need for a
reset() method in the actionform. Struts calls this each time before
populating the form. You should use it to clear fields that relate to
checkboxes, otherwise when the user deselects a checkbox it wont be
reflected in the actionForm)

You give all your checkboxes the same name attribute, and when several are
submitted the different values ticked will all be submitted. If your action
form takes a String[] for that field, struts will populate that field in the
ActionForm with an array of the ticked values.

ie: if your html form has (again using the html tag rather than the struts
one - as Im not familiar with its syntax!)
<input type="checkbox" name="bob" value="all"/>
<input type="checkbox" name="bob" value="your"/>
<input type="checkbox" name="bob" value="base"/>
<input type="checkbox" name="bob" value="are"/>
<input type="checkbox" name="bob" value="belong"/>
<input type="checkbox" name="bob" value="to"/>
<input type="checkbox" name="bob" value="us"/>

and the user ticks the first three and submits, the request will have
information to the effect of:

bob=all
bob=your
bob=base

So struts will call setBob(String[] value) with value being a String[]
containing { "all","your","base" }

In terms of doing it in a table, that would just be a case of having each
individual checkbox in a different <td> and those tds belonging to different
rows. Have a look at the iterate tag documentation and do a search of the
archive to find some information on doing nice tables. I believe there are
some third party taglibs that do very nice tables that will work with
struts, though again havent tried them myself. (Im not actually making use
of JSP!)

Hope this helps.


-----Original Message-----
From: Toni Nehme [mailto:tnehme81@hotmail.com]
Sent: Thursday, July 04, 2002 02:35
To: struts-user@jakarta.apache.org
Subject: html:checkbox in a table


Hi Everyone,


Does anyone knows or have an example that displays a table of records with a
checkbox in each row and when user submit the form,
will be able to know which row is checked?

If so,please let me know how to do it or send me an example.


Thanks.



_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>