Hi, I am using struts for my web application. I have a form bean which contains field for Shipping & Billing address details. Now I have a JSP page with <html:form> for entering values into this form bean. Now This page has two sections (billibg & Shipping address) into same form. Now between these two sections I want to add a checkbox with title "Check if shipping address is same as billing." So that when user clicks on checkbox all the fields in the shipping address field gets disabled & when user submitts form, then inside my action class (say Addaddressaction.java) it should check the value of checkbox & decide whether to enter same values into database for both billing & shipping section. How to render checkbox into JSP page. (I dont want to include any special parameter into my formbean's definition for checkbox.) & also how to retrieve value of this checkbox into action class?
If you want to retrieve the value of the checkbox in your action class, you should define a value for it in the form bean. Also, in your form bean's reset method you should set the value to false, because I believe that unchecked checkboxes come back as null or zero length. If you are using a DynaValidatorForm you can set initial="false" and I believe it will work.
Hi, thanx for your reply. I iagree with your reply but in my question I already mentioned that :- "I dont want to include any special parameter into my formbean's definition for checkbox". I just want to define checkbox into my jsp page inside html:form & also it should be accessed inside action class.
thanx. pras
Dom Lassy
Ranch Hand
Joined: May 05, 2006
Posts: 181
posted
0
Originally posted by Prashant Tiwari: "I dont want to include any special parameter into my formbean's definition for checkbox". I just want to define checkbox into my jsp page inside html:form & also it should be accessed inside action class.
I don't know how to do that. Why can't you add another parameter to your formbean? This is the exact purpose of a form bean.
You can check in your Action class if the checkbox parameter is present or absent.
request.getParameter("[checkBoxParamName]");
If the parameter is absent the value you get from the above code is = null which means that the checkbox is unchecked. If the parameter has a value("on" or "true"), then the checkbox is checked.