Struts 1 How to set checkbox default checked
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 ch开发者_如何转开发eck 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?
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"
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.
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" />
精彩评论