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

html:mutlibox uncheck ,check problem

 
Kriti Garg
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am iterating through <login:iterate> ag and inside that i am using <html:mutlibox>.

Sppose user sees three checkboxes there can be three scenarios...
1)Click All(Its fine )
2)Unclick All(Its fine,as i am checkinf if its null then all false)
3) Click some and untouched some other

then multibox send array of only those which are checked and i am unable to track which are unchecked.

As browser doesnot recongnise the unchecked checkboxes...
using a hidden field with same name works for single checkbox but not correctly when used inside a iterate with a multibox.

Even in my reset method of ActionForm i am iterating through my array of checkboxes and setting it to false.

How can i solve this problem.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the <html:multibox> is intended to be used when the property is represented as a string array and you are populating it using checkboxes. In this example:

<html:multibox property="color" value="red" /> <html:multibox property="color" value="blue" />

The ActionForm property color is represented as a string array which could have zero, one, or two elements depending on what is checked. In this scenario, if the resulting array is {"blue"}, you know for sure that the red checkbox was not checked.

If you're using boolean values, you should be using <html:checkbox/>, not <html:multibox>. Example:
<html:checkbox property="hadMeasles" /> <html:checkbox property="hadSmallpox" /> <html:checkbox property="hadMumps" />

If you set all values to false in the reset() method of your ActionForm, when Struts populates the ActionForm ,all boxes checked will have a value of true, and those unchecked will have a value of false. In the above example, if the first checkbox is checked, the form bean's "hadMeasles" property will be true, and all others will be false, provided you have cleared them in your ActionForm's reset() method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic