Understanding problem with check box of form page in session scoped form bean environment:-
- In the above diagram check box is not selected for second request but form bean class object is showing the selected state value for check box related form bean property which is wrong value (showing unmarried person as married person)
- To solve the above diagram problem there are 2 solutions.
Solution1:- Change the form bean class object scope to request form Session. Here for every request is generated by form page one separated new form bean class object will be created so any request cannot utilize previous request data.
Note: – In sol (1) we are not actually solving the problem; we are escaping from the problem by changing form bean scope to “request”.
Solution2:- By working with reset (-) even though the form bean class object scope is Session.
- ActionServlet calls reset (-,-) methods for every request generated by form page before calling setxxx () methods. Programmer generally keeps not selected state values for check box, list box related form bean properties in this reset () method definition.
Note: – Donnot use reset () to set initial values to form bean properties be3 programmer can do this work during the declaration of form bean prepeties.
Prototype of reset () method:-
- Public void reset (ActionMapping mapping, httpServletRequest request)
- Public void reset (ActionMapping mapping, ServletRequest request)
- While overriding reset () method in our form bean class the array type form bean properties of check box, list box properties we need to assign not selected state values by initialize them with at list element size (1) with respect to Details project related details form class (form bean) the reset () must be overridden as shown below when form bean scope is Session.