RE: html:checkbox default value
If I put it in the form bean constructor wouldn't it cause the field value to be always true no matter if the user unchecks it and submit the form. As far as I can recall a checkbox field should be reset to false before the form population. Erez -Original Message- From: Craig McClanahan [mailto:[EMAIL PROTECTED] Sent: Sunday, September 12, 2004 1:38 AM To: Struts Users Mailing List Subject: Re: html:checkbox default value The values displayed on the page are copied from the form bean, so the right answer is to set the value of the schedule property in your form bean to true. This can be done in the form bean constructor (if you want this initial value all the time), or -- more typical for an update scenario -- you can execute a setup action that pre-fills the form bean (perhaps from information loaded from a database) before forwarding to the page. Craig On Sat, 11 Sep 2004 21:53:36 +0200, Erez Efrati [EMAIL PROTECTED] wrote: I am trying to set the default value of a checkbox to 'checked' by putting: html:checkbox property=schedule value=true/ but somehow it does not check it. The produced HTML gives me input type=checkbox .. value=on What am I missing here? Thanks, Erez - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: html:checkbox default value
Erez Efrati wrote the following on 9/12/2004 7:03 AM: If I put it in the form bean constructor wouldn't it cause the field value to be always true no matter if the user unchecks it and submit the form. As far as I can recall a checkbox field should be reset to false before the form population. I believe you would be correct in that if you do set a boolean checkbox property to true in your formBean (either in constructor or by declaration), you will end up with it remaining true if the user 'unchecks' the box on the form. This is because http does not send over the checkbox property if is not checked. This is why I use a setUp method in my Action (like Craig mentioned) and usually I also make sure my boolean properties are reset to false in the reset method of my ActionForm. In the setUp method you could set up your initial ActionForm boolean property to be whatever you wanted (if it's false by default you wouldn't need to do this, but you would still want to make sure you used the reset method to set your boolean back to false if you plan on using Struts form validation). -- Rick - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: html:checkbox default value
Looking in the code, the tag does not provide any way to set/force the default value - only by setting the value on the form bean. A small workaround is to do: c:set target=${quickSearchForm} property=photosOnly value=${true} / Which works. Still the better way is to work with the form and so anyone Who reads this don't get the idea that I am aiming at this way but still it is sometime useful. Not always we have an init action which is especially a pain with a form that belongs to some tile. Erez -Original Message- From: Erez Efrati [mailto:[EMAIL PROTECTED] Sent: Saturday, September 11, 2004 9:54 PM To: 'Struts Users Mailing List' Subject: html:checkbox default value I am trying to set the default value of a checkbox to 'checked' by putting: html:checkbox property=schedule value=true/ but somehow it does not check it. The produced HTML gives me input type=checkbox .. value=on What am I missing here? Thanks, Erez - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: html:checkbox default value
The values displayed on the page are copied from the form bean, so the right answer is to set the value of the schedule property in your form bean to true. This can be done in the form bean constructor (if you want this initial value all the time), or -- more typical for an update scenario -- you can execute a setup action that pre-fills the form bean (perhaps from information loaded from a database) before forwarding to the page. Craig On Sat, 11 Sep 2004 21:53:36 +0200, Erez Efrati [EMAIL PROTECTED] wrote: I am trying to set the default value of a checkbox to 'checked' by putting: html:checkbox property=schedule value=true/ but somehow it does not check it. The produced HTML gives me input type=checkbox .. value=on What am I missing here? Thanks, Erez - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]