Anthony N. Frasso wrote:
Do you need one checkbox or a series of checkboxes?
Just one. :)
For one checkbox you write something like this (from
the article):
<html:checkbox property="married" value="yes"/>
As I understand it, what this tag does is place the
value "yes" into the property "married" of the form
bean associated with this HTML form (actually, "yes"
and "true" for checkboxes will simply place a "true"
boolean value in the boolean property "married").
What it does not do, however, is have the form
initialized to have this checkbox set as true. What I
need is something sort of like the following:
<html:checkbox property="married" value="yes"
initialValue="${myBean.married}" />
If you have property="married" and value="yes", then the checkbox will
be selected iff ${myBean.married} has the value "yes". If the property
doesn't have the value "yes", the checkbox will be cleared. In either
case, if the checkbox is selected when the form is submitted, the
myBean.married property will be set to whatever you specifed in the
'value' attribute.
Does this clear up what I'm looking for?
The generated HTML should look like:
<input type="checkbox" checked="true">
where the value of the "checked" parameter is the
evaluation of "${myBean.married}".
Provided your specified 'value' and the actual property value are the
same, you'll get what you want. Note that there's a special
consideration for checkboxes, though: if a checkbox is de-selected when
the form is submitted, *no* URL parameter will be included for it. As a
result, Struts has no way to automatically clear your form property when
the checkbox is de-selected.
The solution to this is to have your form's reset() method clear the
form property to whatever value you choose to represent the de-selected
state (e.g. "no"). Before you display the page, you should set the
property to "yes" or "no" as appropriate, to get the checkbox
appropriately selected on the page. The reset() method takes care of
making sure the property is 'switched off', and the normal form submit
processing takes care of making sure it's 'switched on' again if the
checkbox was selected.
I hope that didn't add more confusion than clarification :-)
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]