This week's book giveaway is in the Functional programming forum.
We're giving away four copies of Functional Design and Architecture and have Alexander Granin on-line!
See this thread for details.
Win a copy of Functional Design and Architecture this week in the Functional programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

how to display a check box using html:checkbox ?

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to Struts programming. My requirement is to Display a check box in a Page1(with standard display text) and display some additional
information in Page2 if the check box is checked.(should be developed using struts)

i created a Actionform with a boolean variable



In my JSP page1 i am using <html:checkbox> to generate a check box


In my struts-config.xml the scope of this action is set to "Session" (this should be session for some other purpose)

If i check the checkbox for the first time and clicking on the Next button. Page2 gets displayed with the additional text.

On clicking the Back button on page2, it displays page1 with values retained(check box is selected since scope is set as session). On deselecting the checkbox and clicking on the next button, Page2 gets displayed with the additional text. The "displayAddText" does not get toggled when the check box toggles. (whereas the value toggled
for the first time).

what could be the problem? where am i going wrong? please let me know.

Thanks in advance.

Regards,
Ajay.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add the following method to your ActionForm:


This is necessary because of a quirky behavior of HTML. When a checkbox is not checked, no value is returned to the server. That means if the boolean is set to true, it will stay set to true even if the box is unchecked. Since Struts automatically calls the reset method before populating the properties of the ActionForm, the above code makes sure the value starts out as false and only gets set to true if the box is checked.
[ September 13, 2006: Message edited by: Merrill Higginson ]
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic