• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getParameter on checkbox returning null even though it's checked!

 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did search for help in other threads like this one:
https://coderanch.com/t/279386/JSP/java/Checking-Status-Checkbox
However, my problem cannot be resolved by that information.
My JSP has a form, and when it's submitted, some JSP code at the top of the page handles it with this:

etc, etc.
Most of the form fields are being extracted on the back end in a bean, but now I need to add a checkbox to see which bean to use, so I'm trying to do it in the JSP right after the code above:

etc, etc.
The checkbox HTML code looks like this:

The println statement above says that saveAddrString is null even when I check the box! How could this be?
Update: Ok, so I just don't understand something about getting info out of those form fields, because all of the other fields are null as well. Back in the bean code, it gets all that by parsing through request.getInputStream(), so I'm wondering if my code above is attempting to call request.getParameter at a point where that parameter is already reset. That of course would make me wonder why getMethod still returns POST, but no matter...I can swallow that they would follow different rules. So, if getParameter won't work at that point in my code, then is there anything else I can do (client-side Javascript?) to make sure I can check for that field's value in the JSP code before I choose which bean to pass everything to?
[ September 02, 2003: Message edited by: Stephen Huey ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I always create corresponding hidden variables to checkboxes and radio buttons and populate them using javascript I then only check the hidden fields as opposed to the checkbox or radio button
 
Sheriff
Posts: 67746
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


I always create corresponding hidden variables to checkboxes and radio buttons ...


Seems a bit of overkill to me. What's your reasoning?
bear
 
Bear Bibeault
Sheriff
Posts: 67746
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
With regards to the original question, I tried your code in a set of my own JSP pages and everything worked like a charm.
Obvious first question: your checkbox is in the body of the form that is being submitted, yes?
bear
 
Bear Bibeault
Sheriff
Posts: 67746
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
OK, so I just saw your update. (That is, by the way, not a great way to do it. Post updates as new replies to the original topic.)
You should not be processing the input stream by yourself. Either get the params off the request and pass them to the bean, or pass the request to the bean and let it get them with getParameter() itself.
hth,
bear
[ September 02, 2003: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this out the hard way, if you process the input stream, then your data tends to "go away" when you try and do a getParameter. Chalk it up to general strangeness.
 
Bear Bibeault
Sheriff
Posts: 67746
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

Chalk it up to general strangeness.


No strangeness about it really. If you "eat" the input, it's not available to anything else. So don't do it.
hth,
bear
 
reply
    Bookmark Topic Watch Topic
  • New Topic