This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help me regarding struts checkbox issue...

 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic