jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes Struts 2.1.6: Checkbox does not post unchecked values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2.1.6: Checkbox does not post unchecked values" Watch "Struts 2.1.6: Checkbox does not post unchecked values" New topic
Author

Struts 2.1.6: Checkbox does not post unchecked values

Nick Sher
Ranch Hand

Joined: Nov 10, 2008
Posts: 78
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.


Nick
Chris Montgomery
Ranch Hand

Joined: Jan 14, 2004
Posts: 141
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

Joined: Nov 10, 2008
Posts: 78
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

Joined: Jan 10, 2002
Posts: 60755
    
  65

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"?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2.1.6: Checkbox does not post unchecked values
 
Similar Threads
how to populate formbean property using html:checkbox values
Data mismatch between two separate lists in a single iterator in struts2
Handling Multiple check boxes
Urgent Help Needed in JSP
I need help with Checkboxes