You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nicolas Bizard <ni...@gmail.com> on 2005/12/05 21:15:02 UTC

checkbox behavior hard to control?

Hi everyone.

My question is :
I have a strange problem with checkboxes in a formBean :
The form initializes (action /init)
I validate, get my results
I get "back", asking /init, everything is fine, the form shows me my
previous selections but....
when i uncheck or check one of the boxes and validate again, it does
not update the formbean, i still get the same results as previously.

Note that  this only happens with checkboxes. When i update a text
field, the results are updated in the correct way.

Why is that?

Thanks.

sorry for the off-topic email previously sent , by the way
:-s

Nicolas

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


[OT] Re: checkbox behavior hard to control?

Posted by Dave Newton <ne...@pingsite.com>.
Simonin, Bradley K (Brad) wrote:

> I am just curious.  Does this situation occur with the Multibox tag?   
> I guess I don't understand that  when  you uncheck a checkbox sometime 
> the bean is not  updated?

It's an HTTP/browser thing. Only checked checkboxes are sent in a 
request; if a checkbox isn't checked nothing will be sent to the server.



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


Re: checkbox behavior hard to control?

Posted by "Simonin, Bradley K (Brad)" <br...@psl.nmsu.edu>.
Thank you very much.  I forgot about that.

--Brad.

Michael Jouravlev wrote:

>On 12/9/05, Simonin, Bradley K (Brad) <br...@psl.nmsu.edu> wrote:
>  
>
>>I am just curious.  Does this situation occur with the Multibox tag?   I
>>guess I don't understand that  when  you uncheck a checkbox sometime the
>>bean is not  updated?
>>    
>>
>
>Unchecked checkboxes are not sent to the server by browser, not even a
>key with empty value. Only checked ones are sent.
>
>So, before accepting input you clear checkboxes in your code, then you
>process the request. Whatever checked ones you receive, you set their
>corresponding values in the applicaiton. Others are left unset.
>
>Michael.
>
>---------------------------------------------------------------------
>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: checkbox behavior hard to control?

Posted by Michael Jouravlev <jm...@gmail.com>.
On 12/9/05, Simonin, Bradley K (Brad) <br...@psl.nmsu.edu> wrote:
> I am just curious.  Does this situation occur with the Multibox tag?   I
> guess I don't understand that  when  you uncheck a checkbox sometime the
> bean is not  updated?

Unchecked checkboxes are not sent to the server by browser, not even a
key with empty value. Only checked ones are sent.

So, before accepting input you clear checkboxes in your code, then you
process the request. Whatever checked ones you receive, you set their
corresponding values in the applicaiton. Others are left unset.

Michael.

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


Re: checkbox behavior hard to control?

Posted by "Simonin, Bradley K (Brad)" <br...@psl.nmsu.edu>.
Michael Jouravlev wrote:

>On 12/5/05, Nicolas Bizard <ni...@gmail.com> wrote:
>  
>
>>I am not sure what "clear the state" means?
>>I'm also not sure about what to put in reset(), and when it is executed...
>>    
>>
>
>Is this a question?
>
>  
>
>>It seems that the problem is specific to checkboxes :
>>when unchecked, the state is not updated to the bean
>>    
>>
>
>Indeed it does not. Search the FAQ for that.
>
>Michael.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>  
>
I am just curious.  Does this situation occur with the Multibox tag?   I 
guess I don't understand that  when  you uncheck a checkbox sometime the 
bean is not  updated? 

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


Re: checkbox behavior hard to control?

Posted by Michael Jouravlev <jm...@gmail.com>.
On 12/5/05, Nicolas Bizard <ni...@gmail.com> wrote:
> I am not sure what "clear the state" means?
> I'm also not sure about what to put in reset(), and when it is executed...

Is this a question?

> It seems that the problem is specific to checkboxes :
> when unchecked, the state is not updated to the bean

Indeed it does not. Search the FAQ for that.

Michael.

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


Re: checkbox behavior hard to control?

Posted by Nicolas Bizard <ni...@gmail.com>.
I am not sure what "clear the state" means?
I'm also not sure about what to put in reset(), and when it is executed...
should i include a code like this :

reset(){
 this.setCheckedField(false);
}

It seems that the problem is specific to checkboxes :
when unchecked, the state is not updated to the bean
For example, i had this problem before : i had 4 checkboxes, after
validation, trying to read the value of a "left unchecked" chackbox
raised a null pointer exception (following code :)

myBean.get("myUncheckedCheckbox");

If the 4 checkboxes had been checked, everything was fine... If this
helps to help me ;-)


2005/12/5, Laurie Harper <la...@holoweb.net>:
> Nicolas Bizard wrote:
> > Hi everyone.
> >
> > My question is :
> > I have a strange problem with checkboxes in a formBean :
> > The form initializes (action /init)
> > I validate, get my results
> > I get "back", asking /init, everything is fine, the form shows me my
> > previous selections but....
> > when i uncheck or check one of the boxes and validate again, it does
> > not update the formbean, i still get the same results as previously.
> >
> > Note that  this only happens with checkboxes. When i update a text
> > field, the results are updated in the correct way.
> >
> > Why is that?
> >
> > Thanks.
> >
> > sorry for the off-topic email previously sent , by the way
> > :-s
> >
> > Nicolas
>
> Did you remember to clear the state of the checkbox properties in your
> form bean's reset() method?
>
> L.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


--

Nicolas Bizard
-------------------------------------------------------------------


 Live in such a way that you would not be ashamed to sell your parrot
to the town gossip.
  - Will Rogers


nicolasbizard.free.fr

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


Re: checkbox behavior hard to control?

Posted by Laurie Harper <la...@holoweb.net>.
Nicolas Bizard wrote:
> Hi everyone.
> 
> My question is :
> I have a strange problem with checkboxes in a formBean :
> The form initializes (action /init)
> I validate, get my results
> I get "back", asking /init, everything is fine, the form shows me my
> previous selections but....
> when i uncheck or check one of the boxes and validate again, it does
> not update the formbean, i still get the same results as previously.
> 
> Note that  this only happens with checkboxes. When i update a text
> field, the results are updated in the correct way.
> 
> Why is that?
> 
> Thanks.
> 
> sorry for the off-topic email previously sent , by the way
> :-s
> 
> Nicolas

Did you remember to clear the state of the checkbox properties in your 
form bean's reset() method?

L.


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