You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Franck <fl...@orangecaraibe.com> on 2003/12/29 22:13:02 UTC

Boolean checkbox in session form

Hi,

I'm becoming mad ...

Explain : to handle ActionForm boolean properties with HTML checkbox, we
"need"
To initialize the property as "false" in the reset() method of the
ActionForm .. Ok

Now, if the Action form is defined in the session scope in the
struts-config file
The first time the action is called, the bean is put in session scope.

The next time (eg submit of another form on the same page), the bean is
readed from session scope (RequestProcessor.processActionForm) ... ok
After that, the reset() method is called
(RequestProcessor.processPopulate)

So it's impossible to keep the boolean property as "true" ....

How can I store the form bean in the session scope with a "true" boolean
property ?
Or maybe is there a way to not initialize the boolean properties as
"false" (and update them with checkboxes )

Is my problem understandable ??

Thanks ...

Franck Lefebure
equipe web http://www.orangecaraibe.com
collaborateur http://www.synaxis-partner.com
mailto:flefebure@synaxis-partner.com
 


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


RE: Boolean checkbox in session form

Posted by Guillermo Meyer <gm...@sib.interbanking.com.ar>.
In my particular case (not saying its the general case) I was having a
DispatchAction in a wizard navigation, going forwards and backwards, and
a form in session. In one page, I turn the checkbox on, and then, when I
wanted to turn it off (for, example, if turning it on was wrong and in
this wizard you want to correct this) the off was never sent. And if in
the reset y have to turn it off I would set it to false when I shouldnt
(very very complicated).

So that's why I made this tag extension. I map this property to a
boolean one. I'm attaching the code just in case anyone is interested.

Have a nice year!
Guillermo.


-----Original Message-----
From: Craig R. McClanahan [mailto:craigmcc@apache.org] 
Sent: Lunes, 29 de Diciembre de 2003 07:13 p.m.
To: Struts Users Mailing List
Subject: RE: Boolean checkbox in session form


Quoting Tim Lucia <ti...@yahoo.com>:

> Care to share?  This would be a very, very useful extension.
> 
> Is there any plan(s) for future Struts release(s) to support some 
> attribute of this sort?  Something like "forceFalse='true'" or 
> "forceValue='true'".
> 
> Tim
> 

Guillermo is trying work too hard.

The standard approach to dealing with boolean form bean properties
(presented by a checkbox) is to set the boolean property to false in the
reset method of your form bean, which is called every time the form is
submitted.  If the user checked the box, then the property will be set
to true in processPopulate().

Now, if you want to reset the property again before forwarding back to
the same page again (so that it's always rendered as unchecked when the
page is displayed), just have your Action set the boolean property to
false.  That is what controls how the checkbox is rendered -- in EXACTLY
the same way that an Action can preconfigure any other form field by
setting the corresponding form bean property before fowarding to the
page.

Craig McClanahan


> > -----Original Message-----
> > From: Guillermo Meyer [mailto:gmeyer@sib.interbanking.com.ar]
> > Sent: Monday, December 29, 2003 4:40 PM
> > To: 'Struts Users Mailing List'
> > Subject: RE: Boolean checkbox in session form
> > 
> > 
> > To solve this problem, i created a new taglib for checkbox
> > (extending BaseFieldTag), that creates a hidden input with a 
> > value of true|false and an auxiliary checkbox (named as 
> > <propertyName> + _chk) with a javascript handler that checks 
> > on checkbox value to set true or false to the hidden field, 
> > so always is posted a true or a false value from UI and set 
> > to the appropiate form attribute, and this way you can avoid 
> > reseting value in reset form.
> > 
> > -----Original Message-----
> > From: Franck [mailto:flefebure2@orangecaraibe.com]
> > Sent: Lunes, 29 de Diciembre de 2003 06:13 p.m.
> > To: 'Struts Users Mailing List'
> > Subject: Boolean checkbox in session form
> > 
> > 
> > Hi,
> > 
> > I'm becoming mad ...
> > 
> > Explain : to handle ActionForm boolean properties with HTML
> > checkbox, we "need" To initialize the property as "false" in 
> > the reset() method of the ActionForm .. Ok
> > 
> > Now, if the Action form is defined in the session scope in
> > the struts-config file The first time the action is called, 
> > the bean is put in session scope.
> > 
> > The next time (eg submit of another form on the same page),
> > the bean is readed from session scope 
> > (RequestProcessor.processActionForm) ... ok After that, the 
> > reset() method is called
> > (RequestProcessor.processPopulate)
> > 
> > So it's impossible to keep the boolean property as "true" ....
> > 
> > How can I store the form bean in the session scope with a
> > "true" boolean property ? Or maybe is there a way to not 
> > initialize the boolean properties as "false" (and update them 
> > with checkboxes )
> > 
> > Is my problem understandable ??
> > 
> > Thanks ...
> > 
> > Franck Lefebure
> > equipe web http://www.orangecaraibe.com
> > collaborateur http://www.synaxis-partner.com
> mailto:flefebure@synaxis-partner.com
>  
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 




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


RE: Boolean checkbox in session form

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Quoting Tim Lucia <ti...@yahoo.com>:

> Care to share?  This would be a very, very useful extension.
> 
> Is there any plan(s) for future Struts release(s) to support some
> attribute of this sort?  Something like "forceFalse='true'" or
> "forceValue='true'".
> 
> Tim
> 

Guillermo is trying work too hard.

The standard approach to dealing with boolean form bean properties (presented by
a checkbox) is to set the boolean property to false in the reset method of your
form bean, which is called every time the form is submitted.  If the user
checked the box, then the property will be set to true in processPopulate().

Now, if you want to reset the property again before forwarding back to the same
page again (so that it's always rendered as unchecked when the page is
displayed), just have your Action set the boolean property to false.  That is
what controls how the checkbox is rendered -- in EXACTLY the same way that an
Action can preconfigure any other form field by setting the corresponding form
bean property before fowarding to the page.

Craig McClanahan


> > -----Original Message-----
> > From: Guillermo Meyer [mailto:gmeyer@sib.interbanking.com.ar] 
> > Sent: Monday, December 29, 2003 4:40 PM
> > To: 'Struts Users Mailing List'
> > Subject: RE: Boolean checkbox in session form
> > 
> > 
> > To solve this problem, i created a new taglib for checkbox 
> > (extending BaseFieldTag), that creates a hidden input with a 
> > value of true|false and an auxiliary checkbox (named as 
> > <propertyName> + _chk) with a javascript handler that checks 
> > on checkbox value to set true or false to the hidden field, 
> > so always is posted a true or a false value from UI and set 
> > to the appropiate form attribute, and this way you can avoid 
> > reseting value in reset form.
> > 
> > -----Original Message-----
> > From: Franck [mailto:flefebure2@orangecaraibe.com] 
> > Sent: Lunes, 29 de Diciembre de 2003 06:13 p.m.
> > To: 'Struts Users Mailing List'
> > Subject: Boolean checkbox in session form
> > 
> > 
> > Hi,
> > 
> > I'm becoming mad ...
> > 
> > Explain : to handle ActionForm boolean properties with HTML 
> > checkbox, we "need" To initialize the property as "false" in 
> > the reset() method of the ActionForm .. Ok
> > 
> > Now, if the Action form is defined in the session scope in 
> > the struts-config file The first time the action is called, 
> > the bean is put in session scope.
> > 
> > The next time (eg submit of another form on the same page), 
> > the bean is readed from session scope 
> > (RequestProcessor.processActionForm) ... ok After that, the 
> > reset() method is called
> > (RequestProcessor.processPopulate)
> > 
> > So it's impossible to keep the boolean property as "true" ....
> > 
> > How can I store the form bean in the session scope with a 
> > "true" boolean property ? Or maybe is there a way to not 
> > initialize the boolean properties as "false" (and update them 
> > with checkboxes )
> > 
> > Is my problem understandable ??
> > 
> > Thanks ...
> > 
> > Franck Lefebure
> > equipe web http://www.orangecaraibe.com
> > collaborateur http://www.synaxis-partner.com 
> mailto:flefebure@synaxis-partner.com
>  
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 




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


RE: Boolean checkbox in session form

Posted by Tim Lucia <ti...@yahoo.com>.
Care to share?  This would be a very, very useful extension.

Is there any plan(s) for future Struts release(s) to support some
attribute of this sort?  Something like "forceFalse='true'" or
"forceValue='true'".

Tim

> -----Original Message-----
> From: Guillermo Meyer [mailto:gmeyer@sib.interbanking.com.ar] 
> Sent: Monday, December 29, 2003 4:40 PM
> To: 'Struts Users Mailing List'
> Subject: RE: Boolean checkbox in session form
> 
> 
> To solve this problem, i created a new taglib for checkbox 
> (extending BaseFieldTag), that creates a hidden input with a 
> value of true|false and an auxiliary checkbox (named as 
> <propertyName> + _chk) with a javascript handler that checks 
> on checkbox value to set true or false to the hidden field, 
> so always is posted a true or a false value from UI and set 
> to the appropiate form attribute, and this way you can avoid 
> reseting value in reset form.
> 
> -----Original Message-----
> From: Franck [mailto:flefebure2@orangecaraibe.com] 
> Sent: Lunes, 29 de Diciembre de 2003 06:13 p.m.
> To: 'Struts Users Mailing List'
> Subject: Boolean checkbox in session form
> 
> 
> Hi,
> 
> I'm becoming mad ...
> 
> Explain : to handle ActionForm boolean properties with HTML 
> checkbox, we "need" To initialize the property as "false" in 
> the reset() method of the ActionForm .. Ok
> 
> Now, if the Action form is defined in the session scope in 
> the struts-config file The first time the action is called, 
> the bean is put in session scope.
> 
> The next time (eg submit of another form on the same page), 
> the bean is readed from session scope 
> (RequestProcessor.processActionForm) ... ok After that, the 
> reset() method is called
> (RequestProcessor.processPopulate)
> 
> So it's impossible to keep the boolean property as "true" ....
> 
> How can I store the form bean in the session scope with a 
> "true" boolean property ? Or maybe is there a way to not 
> initialize the boolean properties as "false" (and update them 
> with checkboxes )
> 
> Is my problem understandable ??
> 
> Thanks ...
> 
> Franck Lefebure
> equipe web http://www.orangecaraibe.com
> collaborateur http://www.synaxis-partner.com 
mailto:flefebure@synaxis-partner.com
 


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



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



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


RE: Boolean checkbox in session form

Posted by Guillermo Meyer <gm...@sib.interbanking.com.ar>.
To solve this problem, i created a new taglib for checkbox (extending
BaseFieldTag), that creates a hidden input with a value of true|false
and an auxiliary checkbox (named as <propertyName> + _chk) with a
javascript handler that checks on checkbox value to set true or false to
the hidden field, so always is posted a true or a false value from UI
and set to the appropiate form attribute, and this way you can avoid
reseting value in reset form.

-----Original Message-----
From: Franck [mailto:flefebure2@orangecaraibe.com] 
Sent: Lunes, 29 de Diciembre de 2003 06:13 p.m.
To: 'Struts Users Mailing List'
Subject: Boolean checkbox in session form


Hi,

I'm becoming mad ...

Explain : to handle ActionForm boolean properties with HTML checkbox, we
"need" To initialize the property as "false" in the reset() method of
the ActionForm .. Ok

Now, if the Action form is defined in the session scope in the
struts-config file The first time the action is called, the bean is put
in session scope.

The next time (eg submit of another form on the same page), the bean is
readed from session scope (RequestProcessor.processActionForm) ... ok
After that, the reset() method is called
(RequestProcessor.processPopulate)

So it's impossible to keep the boolean property as "true" ....

How can I store the form bean in the session scope with a "true" boolean
property ? Or maybe is there a way to not initialize the boolean
properties as "false" (and update them with checkboxes )

Is my problem understandable ??

Thanks ...

Franck Lefebure
equipe web http://www.orangecaraibe.com
collaborateur http://www.synaxis-partner.com
mailto:flefebure@synaxis-partner.com
 


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



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