This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to deselct a checkbox after coming back to same JSP

 
a kishore
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
a kishore
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Salil by confirming that reset() is not working.

I will try to set scope as request.


thanks again,
kishore
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic