File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Using checkBoxlist in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Using checkBoxlist in struts2" Watch "Using checkBoxlist in struts2" New topic
Author

Using checkBoxlist in struts2

antonio rega
Greenhorn

Joined: Feb 22, 2010
Posts: 3
Hi,

i have a question about how to use checkBoxlist in struts2:
it's possible populate a checkBoxlist reading value and checking box from database table.
Es: i have a table named Abilitazioni with this value :
idProfilo idFunzione Abilitato
1 1 YES
1 2 YES
1 3 NO
I'dlike to show the first and the second value in the checkboxlist checked, but I'don't know how to.

Thanks
Antonio
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Use the action property (loaded from the DB) as the "name" attribute argument (or "key", depending on how you're using the tag).
antonio rega
Greenhorn

Joined: Feb 22, 2010
Posts: 3
David Newton wrote:Use the action property (loaded from the DB) as the "name" attribute argument (or "key", depending on how you're using the tag).


thanks for replay
I'm new with struts2.....
my tag is like this : <s:checkboxlist name="Abilitazioni" label="Abilitazioni" list="FunzioniAbil" listKey="id" listValue="description"/>
where listKey="id" id is value true o false but the checkboxlist item aren't checked....
What's wrong?

antonio

Lucas Grijander
Greenhorn

Joined: Feb 10, 2009
Posts: 9
you have to convert your Abilitazioni value from YES to true and from NO to false
antonio rega
Greenhorn

Joined: Feb 22, 2010
Posts: 3
Lucas Grijander wrote:you have to convert your Abilitazioni value from YES to true and from NO to false


I've already done but it doesn't work anyway....
where can I find an example to understand how works ?

thanks
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

Hi antonio rega,

I think in this scenario, we can use checkbox tags.
like



In the above code name of the field will be same for all the checkboxes/rows, fieldValue will be the id(UNIQUE) . And in action class you can use checkbox field as array type.

that is like


and its setter and getter methods.

In action checkboxField1 array will have the fieldValues of ONLY selected check boxes.
--
A.A.Anbarasu


A.A.Anbarasu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using checkBoxlist in struts2