This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Struts 2.1.6: Checkbox does not post unchecked values

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"?
 
It's just a flesh wound! Or a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic