I ran into this scenario.
class MyForm extends IdSelectionForm {
private Boolean approveIt = true;
.....
}
my JSTL form consists of
<html:checkbox property="approveIt" styleId="style1" value="true"/>
When I select checkbox and submit. In struts action I get true value set for this field. And again when I uncheck it and submit. Then also I get true value. I am wondering if it is something with default value. Should it be overridden by false when I uncheck.
First of all, <html:checkbox>
is a Struts tag not a JSTL tag. This tag simply generates a standard HTML input of type checkbox. And HTML checkboxes send their value as parameter value when they're checked, and don't send any parameter when they're unchecked.
So, since the default value of your form field is true:
The default value of the approveIt
property should be false. That way, if the checkbox is unchecked, it will keep its default value (false), which is correct. And if the checkbox is checked, it will be set to true, which is also correct.
I was having the same problem. The problem persisted even after the boolean variable was initialized to false.
The problem was my scope was session
.
Upon changing the scope to request
everything works as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With