File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes how to deselct a checkbox after coming back to same JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to deselct a checkbox after coming back to same JSP" Watch "how to deselct a checkbox after coming back to same JSP" New topic
Author

how to deselct a checkbox after coming back to same JSP

a kishore
Ranch Hand

Joined: Sep 16, 2009
Posts: 82
Hi All,

i have a search button in my jsp. i manage to display dynamic checkboxes using the following code.
my problem is once i get the results and come back to same jsp, still the old selected checkboxes remain selected.
i want to deselect those checkboxes. Any one know about this, please guide me in this issue.



thanks in advance
kishore
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

Hey a kishore,

I believe, you are keeping your form object in session that is why while retuning back, you see the check box as selected. you can resolve this problem by keeping the form object in request so that each time you get a new form.

You shall have to make corresponding setting in struts-config.xml .You shall have to add another attribute scope ="request" in corresponding action and any other action which uses that form.

I hope this would resolve your problem


Regards
Salil Verma
a kishore
Ranch Hand

Joined: Sep 16, 2009
Posts: 82
Hi Salil,

thanks for replying.

what you guessed was exactly right. but im adding my formbean to an arraylist in my action class and i set to request. now i get null pointer exception..

any other solution.. ?


thanks,
kishore
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

Hi A,

Just try to find out why and where that null pointer exception is occuring. Is it because of missing checkbox value or something else.
If it is really because of missing checkbox value, then you should check the validity of that condition.

If you want to keep the form been in the session and still want the checkbox to be unchecked at each time you access the jsp, you shall have to override the reset method of the formbean. In reset method set the bean property which stores the values of check box to null.

I think, this would help you.
a kishore
Ranch Hand

Joined: Sep 16, 2009
Posts: 82
Hi Salil,


I already tried that, even then it is not working for me. i followed in this way in my jsp:


where as in form bean, i rest like this:


im not sure, whether im following correct way or not?


thanks,
kishore
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

Hey A,

I tried again at my end and came to know that reset does not work well in this case.You might still be getting the checkbox selected. The best solution would be to keep the scope as request and try to find out and fix why and where the null pointer exception is occuring.
a kishore
Ranch Hand

Joined: Sep 16, 2009
Posts: 82
Thank you Salil by confirming that reset() is not working.

I will try to set scope as request.


thanks again,
kishore
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to deselct a checkbox after coming back to same JSP