wood burning stoves 2.0*
The moose likes Struts and the fly likes how to display a check box using html:checkbox ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to display a check box using html:checkbox ?" Watch "how to display a check box using html:checkbox ?" New topic

how to display a check box using html:checkbox ?

Ajay Xavier
Ranch Hand

Joined: Jan 03, 2005
Posts: 109

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.

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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 ]

Consultant, Sima Solutions
I agree. Here's the link: http://aspose.com/file-tools
subject: how to display a check box using html:checkbox ?
Similar Threads
actionlistener for selectBooleanCheckbox doubt?
how to populate formbean property using html:checkbox values
Display checkbox intially checked
How to return to the last page in failure
URGENT ! Trouble using CHECKBOX