Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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

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.

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 ]
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic