You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Zoran Avtarovski <zo...@sparecreative.com> on 2007/04/20 15:11:54 UTC

[s2] Problem with no checkboxes selected

I've run into a problem where when I edit a form which has check boxes.

1. If I create a new object via the form and have no check boxes selected it
works fine.

2. If I create a new object via the form and have one or more check boxes
selected it works fine.

3. If I edit an object which has had one or more check boxes selected and
deselect all the check boxes the object retains the previous values for the
check box variable.

This clearly has something to with the fact the setter method is not being
called if no check boxes are selected and my object values are somehow
persisting beyond the request. What am I doing wrong here and is there a
work around to this?

Please any pointers on this would be appreciated.


Z.



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


Re: [s2] Problem with no checkboxes selected

Posted by Zoran Avtarovski <zo...@sparecreative.com>.
I have a solution, but it's not pretty. What I ended up having to do is set
a hidden attribute with the same name as my check boxes and set it's value
to -1 as below.

  <s:hidden  name="user.roleIds" value="-1"/>

And then in my service layer screen out any roleIds equal to -1.

As I said not pretty. I'd appreciate a better option.

Z.

> Sorry my response was too quick. I don't always realize the s2 in subject is
> there when I read the posts. I'm not sure how to do this in s2...
> 
> -----Original Message-----
> From: Zoran Avtarovski [mailto:zoran@sparecreative.com]
> Sent: Friday, April 20, 2007 9:29 AM
> To: Struts Users Mailing List; Frank Russo
> Subject: Re: [s2] Problem with no checkboxes selected
> 
> Thanks Frank,
> 
> But I thought that form.reset() was only for s1. Does s2 even have a reset
> method?
> 
> Z.
> 
> 
>> Your form has to implement the ActionForm's reset method. In that
>> method, you should set all of your boolean attributes to false. The
>> reason has to do with http. Only checked checkboxes are submitted on a
>> post request, and only attributes that are submitted have their
>> setters called. If you set everything to false on reset, then the
>> checkboxes that are checked will have their setter's called with true.
>> The unchecked ones will stay false from the reset call...
>> 
>> -----Original Message-----
>> From: Zoran Avtarovski [mailto:zoran@sparecreative.com]
>> Sent: Friday, April 20, 2007 9:12 AM
>> To: Struts Users Mailing List
>> Subject: [s2] Problem with no checkboxes selected
>> 
>> I've run into a problem where when I edit a form which has check boxes.
>> 
>> 1. If I create a new object via the form and have no check boxes
>> selected it works fine.
>> 
>> 2. If I create a new object via the form and have one or more check
>> boxes selected it works fine.
>> 
>> 3. If I edit an object which has had one or more check boxes selected
>> and deselect all the check boxes the object retains the previous
>> values for the check box variable.
>> 
>> This clearly has something to with the fact the setter method is not
>> being called if no check boxes are selected and my object values are
>> somehow persisting beyond the request. What am I doing wrong here and
>> is there a work around to this?
>> 
>> Please any pointers on this would be appreciated.
>> 
>> 
>> Z.
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> 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
>> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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: [s2] Problem with no checkboxes selected

Posted by Frank Russo <Fr...@sas.com>.
Sorry my response was too quick. I don't always realize the s2 in subject is there when I read the posts. I'm not sure how to do this in s2...

-----Original Message-----
From: Zoran Avtarovski [mailto:zoran@sparecreative.com] 
Sent: Friday, April 20, 2007 9:29 AM
To: Struts Users Mailing List; Frank Russo
Subject: Re: [s2] Problem with no checkboxes selected

Thanks Frank,

But I thought that form.reset() was only for s1. Does s2 even have a reset method?

Z.


> Your form has to implement the ActionForm's reset method. In that 
> method, you should set all of your boolean attributes to false. The 
> reason has to do with http. Only checked checkboxes are submitted on a 
> post request, and only attributes that are submitted have their 
> setters called. If you set everything to false on reset, then the 
> checkboxes that are checked will have their setter's called with true. 
> The unchecked ones will stay false from the reset call...
> 
> -----Original Message-----
> From: Zoran Avtarovski [mailto:zoran@sparecreative.com]
> Sent: Friday, April 20, 2007 9:12 AM
> To: Struts Users Mailing List
> Subject: [s2] Problem with no checkboxes selected
> 
> I've run into a problem where when I edit a form which has check boxes.
> 
> 1. If I create a new object via the form and have no check boxes 
> selected it works fine.
> 
> 2. If I create a new object via the form and have one or more check 
> boxes selected it works fine.
> 
> 3. If I edit an object which has had one or more check boxes selected 
> and deselect all the check boxes the object retains the previous 
> values for the check box variable.
> 
> This clearly has something to with the fact the setter method is not 
> being called if no check boxes are selected and my object values are 
> somehow persisting beyond the request. What am I doing wrong here and 
> is there a work around to this?
> 
> Please any pointers on this would be appreciated.
> 
> 
> Z.
> 
> 
> 
> ---------------------------------------------------------------------
> 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
> 



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


Re: [s2] Problem with no checkboxes selected

Posted by Zoran Avtarovski <zo...@sparecreative.com>.
Thanks Frank,

But I thought that form.reset() was only for s1. Does s2 even have a reset
method?

Z.


> Your form has to implement the ActionForm's reset method. In that method, you
> should set all of your boolean attributes to false. The reason has to do with
> http. Only checked checkboxes are submitted on a post request, and only
> attributes that are submitted have their setters called. If you set everything
> to false on reset, then the checkboxes that are checked will have their
> setter's called with true. The unchecked ones will stay false from the reset
> call...
> 
> -----Original Message-----
> From: Zoran Avtarovski [mailto:zoran@sparecreative.com]
> Sent: Friday, April 20, 2007 9:12 AM
> To: Struts Users Mailing List
> Subject: [s2] Problem with no checkboxes selected
> 
> I've run into a problem where when I edit a form which has check boxes.
> 
> 1. If I create a new object via the form and have no check boxes selected it
> works fine.
> 
> 2. If I create a new object via the form and have one or more check boxes
> selected it works fine.
> 
> 3. If I edit an object which has had one or more check boxes selected and
> deselect all the check boxes the object retains the previous values for the
> check box variable.
> 
> This clearly has something to with the fact the setter method is not being
> called if no check boxes are selected and my object values are somehow
> persisting beyond the request. What am I doing wrong here and is there a work
> around to this?
> 
> Please any pointers on this would be appreciated.
> 
> 
> Z.
> 
> 
> 
> ---------------------------------------------------------------------
> 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
> 



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


RE: [s2] Problem with no checkboxes selected

Posted by Frank Russo <Fr...@sas.com>.
Your form has to implement the ActionForm's reset method. In that method, you should set all of your boolean attributes to false. The reason has to do with http. Only checked checkboxes are submitted on a post request, and only attributes that are submitted have their setters called. If you set everything to false on reset, then the checkboxes that are checked will have their setter's called with true. The unchecked ones will stay false from the reset call...

-----Original Message-----
From: Zoran Avtarovski [mailto:zoran@sparecreative.com] 
Sent: Friday, April 20, 2007 9:12 AM
To: Struts Users Mailing List
Subject: [s2] Problem with no checkboxes selected

I've run into a problem where when I edit a form which has check boxes.

1. If I create a new object via the form and have no check boxes selected it works fine.

2. If I create a new object via the form and have one or more check boxes selected it works fine.

3. If I edit an object which has had one or more check boxes selected and deselect all the check boxes the object retains the previous values for the check box variable.

This clearly has something to with the fact the setter method is not being called if no check boxes are selected and my object values are somehow persisting beyond the request. What am I doing wrong here and is there a work around to this?

Please any pointers on this would be appreciated.


Z.



---------------------------------------------------------------------
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