Reputation: 309
I'm making some small changes to an existing project, which was built using Struts 1.2. I need to have a check box on the form checked by default. I'm a newbie on Struts.
I understand that I can't set a default value for check boxes on form reset method, in fact it is suggested to set the value to false for checkboxes in reset method. The only way I can think of is to check the POST param, but I don't think this is a good solution.
Is there a correct Struts way to have a default checked checkbox?
Upvotes: 3
Views: 16704
Reputation: 59
alternatively you can use the ,,normal" html tag to solve this problem. This tag can also interact with the form bean via the name parameter. In the form bean you can use a boolean parameter!
<input type="checkbox" name="multiRole" checked="checked" />
Upvotes: 0
Reputation: 160321
Why can't you set a default value in reset? That's mostly what it's for. You can also set a value in the action that initially displays the form.
Upvotes: 1
Reputation: 306
you have:
<html:checkbox property="multiRole" value="Y" />
if you want the page rendered with it checked by default, you need to set the property "multiRole" in your action form to "Y"
Upvotes: 2