starki78 wrote:
Hi!

I've a large problem with html:multibox.
I've tree checkboxes. When I choose
one or two or three it arrives correct
at the next action!
Only then all checkboxes are deselected
it remembers the state of the checkboxes that was selected before! The state of the form is session in struts-config.
Can you help me with this problem??
I really don't have an idea how to solve it!
As Adam J. mentioned, it sounds like you're using a session-scoped bean. Try overriding (if you haven't already) the reset() method of your form bean and resetting the property:

public void reset( ActionMapping mapping, HttpServletRequest request )
{
   this.values = new String[0];
}

If you're _not_ using a session bean (and are using a request-scoped one instead), you'll _still_ want to do the above. Using this way in both cases, values from the previous request are discarded. If the web browser doesn't send any checkbox values over (because none are checked), then this.values will be an empty array, which corresponds to the very state of the submitted form's checkboxes (ie: none are checked).

The array of values in your formbean for an html:multibox are a list of values of checked checkboxes. So...

1. Form bean looks like this:
this.values = { "value1", "value3", "value5" };

2. Displayed form looks like this:
<html:multibox property="values">value1</html:multibox> 1
<html:multibox property="values">value2</html:multibox> 2
<html:multibox property="values">value3</html:multibox> 3
<html:multibox property="values">value4</html:multibox> 4
<html:multibox property="values">value5</html:multibox> 5

3. HTML sent to browser looks like this:
<input type="checkbox" name="values" value="value1" checked> 1
<input type="checkbox" name="values" value="value1"> 2
<input type="checkbox" name="values" value="value1" checked> 3
<input type="checkbox" name="values" value="value1"> 4
<input type="checkbox" name="values" value="value1" checked> 5

4. User unchecks ALL checkboxes, and submits the form.

5. Struts calls reset() on your form
   - Your reset() method sets this.values = new String[0]

6. Struts populates your form, and _doesn't touch "values"_, because nothing is checked, so values remains an empty array.

Sound good?

- Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to