Struts 1 How to set checkbox default checked

hendry.fu picture hendry.fu · Sep 27, 2011 · Viewed 15k times · Source

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?

Answer

francesco.s picture francesco.s · Sep 27, 2011

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"