• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts 2.1.6: Checkbox does not post unchecked values

 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The landing page of my web application supports pagination and I want the user to be able to select multiple items using checkboxes to perform few operations. The checkboxes are backed by String array, I tried this using sessions.

There is one use case that I am struggling with, and that is:
1. Suppose, the user initially selects two items to delete then I add these to a session attribute,
2. If one of these two items is unchecked and the user submits form, I need to update the session variable but I have no idea about the unchecked values because I don't see the unchecked items in the action class.

How do I overcome this issue?

Here is my code:

JSP:


Action class: The following property has it's getters/setters.


Please advise.
 
Chris Montgomery
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've struggled with these as well. unchecked boxes basically don't exist.
To be honest, I avoid the struts implementation of checkboxes if I need to get 'fancy'.

An alternative is to create your own checkboxes ( this can be done dynamically ) and assign meaningful id's to each of the checkboxs. From there, you can leverage jQuery's select event along with AJAX to deal with the user selection realtime. No form submit necessary...

This exact solution may not be relevant, but hopefully provides you some alternative perspectives on solving your issue.

 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Montgomery wrote:I've struggled with these as well. unchecked boxes basically don't exist.
To be honest, I avoid the struts implementation of checkboxes if I need to get 'fancy'.

An alternative is to create your own checkboxes ( this can be done dynamically ) and assign meaningful id's to each of the checkboxs. From there, you can leverage jQuery's select event along with AJAX to deal with the user selection realtime. No form submit necessary...

This exact solution may not be relevant, but hopefully provides you some alternative perspectives on solving your issue.



Thanks for the reply Chris. It's sad that this simple problem has not been addressed properly yet. This is how I did it:
1. Have hidden fields in the form
2. Action class will receive values of these hidden fields and update a set to correctly reflect which checkboxes have been updated. For example, if hidden fields 1, 2, and 3 are submitted, then all these entries will be removed from the set. The set is again updated with values of checked checkboxes.

This works correctly with pagination.

I am unhappy with this solution as it is adding the overhead of iterating through all the values again and again. I have to be happy with it because it solves my problem.

If anyone has a better solution please share it here.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Sher wrote:It's sad that this simple problem has not been addressed properly yet.

Huh? That's how HTML works. How could it be "addressed"?
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic