You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Galbreath, Mark" <Ga...@tessco.com> on 2002/10/04 14:25:37 UTC

RE: CheckBox and Boolean[] Array - Incorrect Values Submitted Whe n CheckBox is unchecked

I'm not sure what you mean.  If a checkbox or radio button is not checked,
it has NO state.  This means boolean false is never passed.  Only boolean
trues are passed in the request object.  If you are defining individual
objects as boolean in your ActionForm, the JVM assigns their state to false
by default, so any individual object that is passed in the request object
will be true and change the state accordingly.  It may look like your form
is setting your ActionForm booleans to false, but it is not - the JVM is.
This is why it won't work with an array - the JVM sets arrays to null by
default.

Mark

-----Original Message-----
From: Charlesworth, Chico [mailto:Chico.Charlesworth@softwareag.co.uk]
Sent: Friday, October 04, 2002 8:18 AM
To: 'Struts Users Mailing List'
Subject: RE: CheckBox and Boolean[] Array - Incorrect Values Submitted
Whe n CheckBox is unchecked



If that is the case, then why does it work with single boolean properties? I
only get this problem when working with an array.

Chico

-----Original Message-----
From: Galbreath, Mark [mailto:Galbreath@tessco.com] 
Sent: 04 October 2002 13:12
To: 'Struts Users Mailing List'
Subject: RE: CheckBox and Boolean[] Array - Incorrect Values Submitted Whe n
Ch eckBox is unchecked

This is by design and you will have to write some code to accommodate it.
The HTML spec mandates that no request values are passed for unchecked
checkboxes, so you will have to keep track of the checkboxes yourself.  What
I do is type the checkboxes as String rather than boolean in the ActionForm
and track "true" and "false" through the iterator.

Mark

-----Original Message-----
From: Charlesworth, Chico [mailto:Chico.Charlesworth@softwareag.co.uk]
Sent: Friday, October 04, 2002 7:11 AM
To: 'Struts Users Mailing List'
Subject: CheckBox and Boolean[] Array - Incorrect Values Submitted When
Ch eckBox is unchecked



Hi,

I'm trying to iterate through a Boolean Array using logic:iterate and then
display these as check boxes. This works fine, but when submitting the form
and resending the Boolean Array back to the Action class, only the values
that are true are returned.

In the struts documentation it says:
WARNING: In order to correctly recognize unchecked checkboxes, the
ActionForm bean associated with this form must include a statement setting
the corresponding boolean property to false in the reset() method.

But this only implies for a single property.

Is there a workaround or a fix for this?

My jsp code:

<logic:iterate id="flag" name="myForm" property="flags">
<logic:equal name=" flag " value="true">
	<input type="checkbox" id="flags" name="flags" value="on"
checked="checked">
</logic:equal>
<logic:notEqual name=" flag " value="true">
	<input type="checkbox" id="flags" name="flags" value="on">
</logic:notEqual>
</logic:iterate>

Cheers,
Chico.

-- 
The content of this e-mail is confidential, may contain privileged material
and is intended solely for the recipient(s) named above. If you receive this
in error, please notify Software AG immediately and delete this e-mail.

Software AG (UK) Limited
Registered in England & Wales 1310740
Registered Office: Hudson House, Hudson Way,
Pride Park, Derby DE24 8HS

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

-- 
The content of this e-mail is confidential, may contain privileged material
and is intended solely for the recipient(s) named above. If you receive this
in error, please notify Software AG immediately and delete this e-mail.

Software AG (UK) Limited
Registered in England & Wales 1310740
Registered Office: Hudson House, Hudson Way,
Pride Park, Derby DE24 8HS

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>