Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

html-multibox How can i make certain values checked

 
vikram nalagampalli
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
am using <html:multibox> with LabelValueBean[]. the following is the code

<logic:iterate id="IDRequirement" name="InitialPageDetailViewBean" property="IDRequirements">
<html:multibox property="IDRequirementValues">
<bean:write name="IDRequirement" property="value"/>
</html:multibox>
<bean:write name="IDRequirement" property="label"/>
</logic:iterate>
The above code is rendering me all checkboxes with appropriate values. What i am trying to achieve is to make some of this checkboxes Checked based on a list. I am wondering if there is a straight forward way of doing it by passing my list as part of value in Multibox property.

Can any one suggest, how i can do this. I will really appreciate any help as i am nearing a deadline.....
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vikram,
You just need to set that array of Strings to the IDRequirementValues field of InitalPageDetailViewBean.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am now facing to a case that, when the value of the checkboxes is empty string, all boxes are checked.

But somehow the checkboxes really should not have any values, so, any method that I can have the empty value checkbox, but the checkboxes are NOT checked by default?

Nick
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nicholas Cheung:

I am now facing to a case that, when the value of the checkboxes is empty string, all boxes are checked.

But somehow the checkboxes really should not have any values, so, any method that I can have the empty value checkbox, but the checkboxes are NOT checked by default?


If you are using DynamicActionForms, and you are using <html:multibox> where having no boxes checked is a valid state, then you must exten org.apache.struts.action.DynamicActionForm and override reset(), setting your String[] to a new String[] of size 0.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about if I am currently using ValidatorForm?

I have put all the *attributes* inside the Form, and for the checkboxes, I used Hashtable to keep track with it.

I have tried that, if I put a *space* in the *value*, even the real value is empty string, the checkboxes behave naturally. My workmates told me that this is the *default* behaviour of Struts.

Any ideas?

Nick
 
vikram nalagampalli
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All. Appreciate your help.

Jeanne, you helped me get my mental block released.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic