My form runs in session scope.
I have two checks boxes in my form and they are selected by default. But when I uncheck the checkboxes and submit the form, the checkboxes reverts back to the checked state.
What could be causing this? Any hint on fixing this will be greatly appreciated.
FYI: If I change my form scope from session to request, the checkboxes seem too operate fine.
<div class="checkbox_item">
<label>
<input id="member" name="member" type="checkbox" checked="checked" value="Y" ></input>
Member
</label>
</div>
<div class="checkbox_item">
<label>
<input id="candidate" name="candidate" type="checkbox" checked="checked" value="Y" ></input>
Candidate
</label>
</div>
I checked the value of the checkboxes like below before the form is submitted to the servlet and it always shows "Y" for both.
alert("member: " + $("#member").val() + " candidate: " + $("#candidate").val());
EDIT:
I am using Struts 1.
Method that renders the form:
public ActionForward renderForm(ActionMapping actionMapping,
ActionForm form, HttpServletRequest req,
HttpServletResponse res) throws Exception {
MyForm myForm = (MyForm) form;
myForm.set("member", "Y");
myForm.set("candidate", "Y");
return actionMapping.findForward("success");
}
Method that is called when the form is submitted:
public ActionForward search(
ActionMapping actionMapping, ActionForm form,
HttpServletRequest req,
HttpServletResponse res) throws Exception {
MyForm myForm = (MyForm) form;
List<MyObject> list = service.search(myForm);
myForm.setMyList(list);
return actionMapping.findForward("success");
}
My jsp form:
<form name="myForm" action="myLink.do" method="post" onsubmit="return clickSearchButton()">
<label>
<div class="checkbox_item">
<label>
<html:checkbox name="myForm" styleId="member" property="member" value="Y"/>
Member
</label>
</div>
<div class="checkbox_item">
<label>
<html:checkbox name="myForm" styleId="candidate" property="candidate" value="Y"/>
Candidate
</label>
</div>
</label>
<input type="submit" title="Search" />
</form>