File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes multibox and checked values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "multibox and checked values" Watch "multibox and checked values" New topic

multibox and checked values

Jordan Smith
Ranch Hand

Joined: Apr 06, 2008
Posts: 89
I am using the following code to generate a mulibox values:

interestsForm looks like that:

I need to display some of the values as checked.
I will depent it on the data base that I will return in String all the interests that the user alreay has.
I thought to create another variable:
private String[] checkedItems = ... // i will get it from DB;
and if the itme is in the checkedItems - it will display checked next to it.

What is the way to do it?
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
If I'm understanding your problem correctly I think all you need to do is store your DB values in your selectedItems property before the JSP is run.
Subrata Biswas

Joined: Nov 25, 2008
Posts: 9
Try below code -
<logic:iterate id="item" property="items">
<html:multibox property="selectedItems">
<bean:write name="item" />
<beam:write name="item" />

As per above code - you should have two properties in your form/bean. One is items and second one is selectedItems.
if any Item from selectedItems is present inside items that check box will apear as checked else not.

Hope it will solve your issue.
I agree. Here's the link:
subject: multibox and checked values
jQuery in Action, 3rd edition