File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Unchanged dynamically created check boxes not in request object. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Unchanged dynamically created check boxes not in request object." Watch "Unchanged dynamically created check boxes not in request object." New topic
Author

Unchanged dynamically created check boxes not in request object.

Paul Roubekas
Greenhorn

Joined: Jul 17, 2001
Posts: 24
I am creating a dynamic number of checkboxes, all with the same name but different text in the values attribute of the checkbox tag. The problem is I am getting the value for the first(index 0) check box using the

and the value for any checkbox that was changed by the user. But I am not getting the value, (I am getting a blank) for check boxes that were not changed. Giving each checkbox a unique name does not solve the problem either. Any ideas on how to get the values, of the unchanged checkboxes, into the request object?
sreenivas chalam
Greenhorn

Joined: Jul 11, 2002
Posts: 2
firstly, i didn't get why you need the values of unchecked check boxes. but if you want to get them, then you can run a javascript before the form submits, by transfering them into some hidden form fields. then you can access them on the other page.


Sreenivas Chalam<p>** Behave the way you would expect from others **
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
This is well-known browser behavior. It's not just check boxes either, the same thing happens with text fields etc.
When browser forms were first introduced it was seen as a sensible network efficiency move to nt send back values which have not changed. After all, surely whoever wrote the page knows the default values, so no reply is the same as a default reply.
There are several ways round this.
The most robust is to "go with the flow" and accept that unchanged fields will not be returned, and take a note of the initial values (in the session, for example) when you generate the page. Then if you don't get anything back from the browser for a field you just look up the default value from the session.
Other ways include adding a little JavaScript to the page which "tweaks" the values to ensure they all get returned to the server. This is pretty simple with text fields, you just need to add a known prefix to the values, and strip it off in the form handler. It's harder for checkboxes, so it's not really recommended.
How are you generating these "dynamic" checkboxes ?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Paul Roubekas
Greenhorn

Joined: Jul 17, 2001
Posts: 24
I am using custom tags to create the dynamic check boxes. Why then do I get the unchanged values for a SELECT and TEXTAREA that I create at the same time in the same way?

[ July 29, 2002: Message edited by: Paul Roubekas ]
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
CheckBox and option button values are not sent to the back end at all if they are not checked. Textboxes send a null for the value if nothing is entered.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unchanged dynamically created check boxes not in request object.
 
Similar Threads
Problem While using check boxes
How to Get the check box in html:checkbox automatically get checked on display .
html-multibox How can i make certain values checked
problem in getting values using EL
Kindly help me with this checkbox issue