File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Please help me regarding struts checkbox issue... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Please help me regarding struts checkbox issue..." Watch "Please help me regarding struts checkbox issue..." New topic
Author

Please help me regarding struts checkbox issue...

Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
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?

Thanx in advance.
Prash


********Deserve Before You Desire********
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
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.

http://struts.apache.org/1.2.7/userGuide/struts-html.html#checkbox
Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
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
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.
Zip Ped
Ranch Hand

Joined: Jul 26, 2005
Posts: 336
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.
 
Consider Paul's rocket mass heater.
 
subject: Please help me regarding struts checkbox issue...
 
Similar Threads
How to set from variables to Bean?
Struts : checkbox status is unchanged if i use back button and uncheck it
Validation rule triggered for readonly or disabled textboxes
Struts: checkbox's previous value remains if i go back and unselect it
i need help how to link radiobutton and textarea using struts tld