aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Struts : checkbox status is unchanged if i use back button and uncheck it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Struts : checkbox status is unchanged if i use back button and uncheck it" Watch "Struts : checkbox status is unchanged if i use back button and uncheck it" New topic
Author

Struts : checkbox status is unchanged if i use back button and uncheck it

Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
hi
I have a couple of checkboxes in a jsp page used in struts framework. I am using DynaValidatorForm as form bean with session scope, so it means the properties are mapped only in the struts-config.xml. the checkboxes' property names are checkbox1 and checkbox2.
now the in the action class, i do:

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception {DynaValidatorForm dynaform = (DynaValidatorForm)form; System.out.println("1st checkbox value:"+ dynaform.get("checkbox1") ); System.out.println("2nd checkbox value:"+ dynaform.get("checkbox2") ); .....}


Now if I check the first checkbox and press on submit button, the action class prints out:

1st checkbox value: on
2nd checkbox value: off

this is as expected

Now I click on the back button, then i uncheck the first checkbox and click on submit.
the output is same as before, i.e.:
1st checkbox value: on //wrong
2nd checkbox value: off

I expected it to be
1st checkbox value: off
2nd checkbox value: off

That means if in a session if i check on checkbox 'on', and i go back and uncheck it, the uncheck is never stored, i.e. the property is never set to 'off' .
Now if i check the second one, and click on submit, output is :
1st checkbox value: on //expected off
2nd checkbox value: on //correct

now i go back and uncheck the 2nd checkbox (the first checkbox is already unchecked before), click submit and i get this output:

1st checkbox value: on //expected off
2nd checkbox value: on //expected off

Please let me know what is happening. I expect the values of uncheck boxes to be 'off' when i go back and uncheck them.
thanks
Tanveer
Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
ok
i got one solution, i.e to use a array of string in the dyna action form definition in struts-config.xm:

<form-property name="companies" type="java.lang.String[]"/>

then i write the jsp as:

<html:checkbox property="companies" value="CanadaLife"/>CanadaLife<br>
<html:checkbox property="companies" value="Eagle Star"/>Eagle Star<br>
<html:checkbox property="companies" value="Hibernian"/>Hibernian<br>
<html:checkbox property="companies" value="Irish Life"/>Irish Life<br>
<html:checkbox property="companies" value="New Ireland"/>New Ireland<br>

this way i will get an array of String when i do ((DynaValidateForm)form).get("companies");
I will have ti iterate thru the array and compare their values to know which ones are selected(i.e. which ones are in the array). Those not in the array means they were not selected
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts : checkbox status is unchanged if i use back button and uncheck it
 
Similar Threads
Checkbox issue
how to show whick checkbox is checked in jsp page without submit?
checkboxes from a query , How to ?????
Struts: checkbox's previous value remains if i go back and unselect it
how to do