wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts2 checkbox problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 checkbox problem" Watch "Struts2 checkbox problem" New topic
Author

Struts2 checkbox problem

Sid Majumdar
Greenhorn

Joined: Apr 22, 2010
Posts: 3
hello,

We have a peculiar checkbox problem with struts2 when onf of our web application is trying to render the checkbox tags.

The problem we are facing is, when we submit the form associated with those checkboxes, for some reason, sometimes, all the checkboxes on that page get selected. Now this is a random behaviour and although we can recreate this problem, it's intermittent. We don't use multibox or the checkboxlist tag and i am not sure if that would help in this case.

I looked at the post parameters sent to the server on form submit, and i observed that all the hidden variables associated with those checkboxes (inherent to struts), have a value of 'true' by default.
Something similar to '__checkbox_bean1.bean2.bean3.isVariable[true]. So, looks like the hidden parameter is true by default and then if the user hasn't selected the checkbox, it (struts - checkboxinterceptor) will assign the value false. Please correct me if i am wrong here.
Hence if i go by that theory, at certain times when the issue can be recreated, this value is not set to false and all the checkboxes get selected. But this does not seem right, as the interceptor does execute each time or any interceptor for that matter.

I am trying to figure out if, someone has faced this problem before and/or has any ideas/solutions on how i can debug this from a struts/app perspective.
Let me know if you would need any additional information in this regard. I am not at liberty to share the code, but i can generalize the code snippets if need be.
Appreciate your help in this matter.

Thanks Sid
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Something similar to '__checkbox_bean1.bean2.bean3.isVariable[true]. So, looks like the hidden parameter is true by default and then if the user hasn't selected the checkbox, it (struts - checkboxinterceptor) will assign the value false. Please correct me if i am wrong here.

It'd assign "true" if that's what the hidden value is.
Sid Majumdar
Greenhorn

Joined: Apr 22, 2010
Posts: 3
Is there any way i can find out the checkbox values on the ValueStack at runtime?

More importantly, i need to find out which file/code is trying to set it at that instant.
Deepak Prakash
Greenhorn

Joined: Apr 11, 2010
Posts: 13
1. Check what is the default value which is initialised in bean3 for isVariable
2. Use a script(preferably JS) to alert/print the value of checkbox on page load and on page submission.
3. Check if the value(s) is/are read from wrong property instead of checkbox property.
4. Are you using value attribute in checkbox tag ?
Sid Majumdar
Greenhorn

Joined: Apr 22, 2010
Posts: 3
Appreciate your prompt response Deepak!

Here is how we have defined one of these checkboxes


where w.x.y.z represents a nested bean property.

Javascript may not be helpful here, as i did check the form parameters, and i didn't see the values being sent across to the server when all of these get selected automatically. So it's got something to do on the server rather than the client.

The default value initialized in the bean is 'false'.

how do i check if struts is reading the right value each time from the ValueStack and who is updating that property each time?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 checkbox problem