Sorry about that - here is the code again - there should be a zip file
attached.  I do not think that this code is going to be included in
Struts because it relies on some java script and therefore may not be
100% with all browsers, and would not work if a user disable j.s.
However it works well for us as we have control over the user
environment.


Laine


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 09, 2001 1:45 PM
To: [EMAIL PROTECTED]
Subject: Re: Unchecking radio buttons?




Thanks for that (although I don't like inserting scriptlets!).

My problem, though, is that the underlying value in my form bean is not
being
displayed in the checkbox - it is set to FALSE, and yet the box appears
checked.

Is this an error in Struts?  Also, am concerned that the HTML spec is
not being
implemented with the "checked" attribute being unavailable.  Wouldn't it
be easy
to add?

Laine, is the code you submitted going to be added to Struts?  I didn't
get any
code in the mail by the way!

Cheers,

Dave




"Spencer Smith" <[EMAIL PROTECTED]> on
05/08/2001
05:44:30 PM

Please respond to [EMAIL PROTECTED]

To:   [EMAIL PROTECTED]
cc:    (bcc: David Hay/Lex/Lexmark)
Subject:  Re: Unchecking radio buttons?




All you really have to do is to manually set the checkbox value to false
after you display the current value:

ie:

<html:checkbox property="mycheckbox" />       // notice that no value is
set
<% MyForm.setMycheckbox(false) %>        // do this after you display
the
above line in same JSP

where:

protected boolean mycheckbox;    // mycheckbox is of type boolean (small
b)

and you're in business.  If the checkbox is already checked it will
still be
checked when you do a submit, because it will read the value on the
page.
If you uncheck it though, it will be false which is correct too.

:-)




----- Original Message -----
From: "Laine Donlan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, May 08, 2001 2:30 PM
Subject: RE: Unchecking radio buttons?


Here is some code that I submitted to the dev list a while back. It
might be useful as it solves the problem of the 'unchecked' checkbox
submit.  Hope it helps.

Laine

-----------------------------------------

In order to capture the act of a user unchecking checkboxes and to
initialize the checkbox as checked/unchecked with non boolean values I
made a couple of changes to the
org.apache.struts.taglib.html.CheckboxTag.

Basically the changes consisted of:

1) Using the supplied value attribute to match against the bean property
value and generating the 'checked' attribute accordingly.  If the value
is not supplied then the previously implemented method of checking 'on',
'true', or 'yes' is performed.  So I do not think that default behavior
should be affected.

2) Added support for two new attributes - submitUnchecked (boolean) and
uncheckedValue (String).  Neither of these attributes are required and
the submitUnchecked defaults to 'false'.  If a user chooses to submit
unchecked values then two form inputs will be generated that facilitate
this function.  See below for an example:

Tag notation -
<html:checkbox  name="bean" property="indexedBean.property"
submitUnchecked="true" uncheckedValue="0" value="1"/>

Generated HTML -
<input type="checkbox" name="indexedBean.property_checkBox" value="1"

onclick="(this.checked?this.form['indexedBean.property'].value='1':this.
form['indexedBean.property'].value='0')">
<input type="hidden" name="indexedBean.property" value="0"/> (where 0 is
the current value of the bean property)

So in this scenario the actual checkbox param in the request will be
ignored and the hidden input will be used to maintain the bean property
that the user wishes.

In the case where the user does not provide the two new attributes the
html will be generated as it is today with the exception of the
determination of the checked or unchecked mentioned above.

I could not see how this functionality was present in the current
checkbox tag without explicitly declaring two tags and adding javascript
to the checkbox tag.  Even then some scripting may be required to
differentiate between the two inputs and to initialize the hidden one.
If I missed something could someone point me in the right direction.  I
have attached the CheckboxTag.java file for review and use if anyone is
interested.

Thanks.  Comments would be appreciated.

Laine



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 08, 2001 5:12 PM
To: [EMAIL PROTECTED]
Subject: Re: Unchecking radio buttons?




thanks for the replies.

Yes, I need the checkbox capabilities, not radio buttons.

Question with these, though - is there an equivalent to the "checked"
attribute
in HTML reference speck?

I am creating checkbox with the following:  <html:checkbox
property="notFolders"
value="true"/>, and underlying value of notFolders is "false".  Would
therefore
expect checkbox to appear as unchecked, and True to be submitted is
checkbox is
clicked.

Showing up as already checked, however.

Would appreciate any help...

Dave











CheckboxTag.zip

Reply via email to