You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Gordon <ad...@readytalk.com> on 2006/08/10 18:28:10 UTC

html:checkbox issue

I'm sure this is a coding problem (they usually are...) on the server-side:

I've got an html:checkbox in a form and the property is mapped/spelled 
correctly to the field/method in the bean.  The behavior I am seeing is 
that the bean property (a boolean) is not being set based on the state 
of the checkbox.

I fired up Ethereal and following the TCP stream from the POST, I can 
see the name of the property being passed (<property name>=on) as a 
parameter on the request if the checkbox is checked, but if it is not 
checked, the parameter doesn't show up at all on the request (I'd 
expected <property name>=off) but this might be the reason that Struts 
can't set the property if it doesn't know the value....

Obviously, I can issue a request.getParameter(<property name>) and if it 
returns null, set the property on the bean myself, but I had hoped 
Struts would do this for me...

Anyone run into this before or have any suggestions?  Thanks.

-- adam


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: html:checkbox issue

Posted by Adam Gordon <ad...@readytalk.com>.
David-

Since I've only one checkbox, I think that's way overkill...regardless, 
I should take back my prior comment about the documentation for struts:

http://struts.apache.org/1.x/struts-taglib/tlddoc/index.html has a 
WARNING about how to make struts have the ability to detect unchecked 
checkboxes.  It's amazing how RTFM results in user education...

Incidentally, I believe this is basically the same as what Kalpesh 
suggests in the follow up email...

-Adam

David Durham wrote:
> Adam Gordon wrote:
>> I've got an html:checkbox in a form and the property is 
>> mapped/spelled correctly to the field/method in the bean.  The 
>> behavior I am seeing is that the bean property (a boolean) is not 
>> being set based on the state of the checkbox.
>>
>> I fired up Ethereal and following the TCP stream from the POST, I can 
>> see the name of the property being passed (<property name>=on) as a 
>> parameter on the request if the checkbox is checked, but if it is not 
>> checked, the parameter doesn't show up at all on the request (I'd 
>> expected <property name>=off) but this might be the reason that 
>> Struts can't set the property if it doesn't know the value....
>>
>> Obviously, I can issue a request.getParameter(<property name>) and if 
>> it returns null, set the property on the bean myself, but I had hoped 
>> Struts would do this for me...
>>
>> Anyone run into this before or have any suggestions?  Thanks.
>
> Try using multibox.  I think it will do what you need.
>
> http://husted.com/struts/tips/007.html
>
> -Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: html:checkbox issue

Posted by David Durham <dd...@vailsys.com>.
Adam Gordon wrote:
> I've got an html:checkbox in a form and the property is mapped/spelled 
> correctly to the field/method in the bean.  The behavior I am seeing is 
> that the bean property (a boolean) is not being set based on the state 
> of the checkbox.
> 
> I fired up Ethereal and following the TCP stream from the POST, I can 
> see the name of the property being passed (<property name>=on) as a 
> parameter on the request if the checkbox is checked, but if it is not 
> checked, the parameter doesn't show up at all on the request (I'd 
> expected <property name>=off) but this might be the reason that Struts 
> can't set the property if it doesn't know the value....
> 
> Obviously, I can issue a request.getParameter(<property name>) and if it 
> returns null, set the property on the bean myself, but I had hoped 
> Struts would do this for me...
> 
> Anyone run into this before or have any suggestions?  Thanks.

Try using multibox.  I think it will do what you need.

http://husted.com/struts/tips/007.html

-Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: html:checkbox issue

Posted by kalpesh modi <mo...@yahoo.com>.
You can keep the default value for the checkbox field to be "off" in the form bean. It will be set to "on" only if the checkbox is checked on the JSP.

Thanks,
-Kalpesh

Adam Gordon <ad...@readytalk.com> wrote: I'm sure this is a coding problem (they usually are...) on the server-side:

I've got an html:checkbox in a form and the property is mapped/spelled 
correctly to the field/method in the bean.  The behavior I am seeing is 
that the bean property (a boolean) is not being set based on the state 
of the checkbox.

I fired up Ethereal and following the TCP stream from the POST, I can 
see the name of the property being passed (
=on) as a 
parameter on the request if the checkbox is checked, but if it is not 
checked, the parameter doesn't show up at all on the request (I'd 
expected 
=off) but this might be the reason that Struts 
can't set the property if it doesn't know the value....

Obviously, I can issue a request.getParameter(
) and if it 
returns null, set the property on the bean myself, but I had hoped 
Struts would do this for me...

Anyone run into this before or have any suggestions?  Thanks.

-- adam


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org






 		
---------------------------------
Stay in the know. Pulse on the new Yahoo.com.  Check it out.