This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts2 checkboxlist prepopulate problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 checkboxlist prepopulate problem" Watch "Struts2 checkboxlist prepopulate problem" New topic

Struts2 checkboxlist prepopulate problem

J Snider

Joined: Feb 02, 2009
Posts: 1
I am unable to figure out how to prepopulate a checkboxlist. The checkboxlist displays fine and works when I insert a record (i see the data in the db), but when I edit that record the checkboxlist is always blank/not populated. Using struts2/hibernate.

Student entity (many-to-many relationship with AwardCriteria)

AwardCriteria entity (many-to-many relationship with Student)

StudentAction - I get all possible criteria items and place them in awardCriteria

JSP checkboxlist - the list is set to awardCriteria (contains all possible criteria options). This allows me to save to the db fine (data in db is correct), but the checkboxlist never prepopulates when I edit a record

How can I get my checkboxlist to prepopulate? Any guidance greatly appreciated. Thanks.
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684


please change in you code at jsp for display chaeck box list.

<s:checkboxlist list="awardCriteria" label="Criteria Items" listKey="id" listValue="name" name="" value="%{id}" />

Just change this value="%{id}"

this will solve your problem.

Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Consider Paul's rocket mass heater.
subject: Struts2 checkboxlist prepopulate problem
Similar Threads
I need help with Hibernate
Struts 2 checkboxlist error - list key could not be resolved
Struts2 Iterator
checkboxlist- items checked
Duplication des labels checkboxlist et optgroup