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 Checkbox value not being passed to bean. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Checkbox value not being passed to bean." Watch "Checkbox value not being passed to bean." New topic
Author

Checkbox value not being passed to bean.

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi Folks,
Im facing a problem where as a part of my project I have to store the values from the form into a bean . Im being able to pass the value of the textboxes successfully however the checkbox is always being set to null .any clues on how I could get this to work?Pardon me , if its a silly error as im relatively new to programming.


This is my jsp


Learning and Learning!-- Java all the way!
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Bounce.Please help!
Sudhakar Sharma
Ranch Hand

Joined: Apr 04, 2009
Posts: 71

Hi,



value attribute is not given, also if checkbox is not selected it is not passed in the parameter.

thanks and regards
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi Sudhakar ,
Thanks for replying . what should i set the value attribute to? Also,is it not set to the bean value when checked on the screen?
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

which value is taking back the value to the action ? if you have created a variable in the action then use that variable in the 'value' attribute use some EL tags to persist it through the request scope.


Time is what we want the most, but what we use the worst. -- William Penn
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Robin John wrote:which value is taking back the value to the action ? if you have created a variable in the action then use that variable in the 'value' attribute use some EL tags to persist it through the request scope.

i dont understand what you mean by 'action' here, are you referring to the bean class?
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

yup if the bean class is the class to which you submit the page....
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Im sorry but I still dont understand . Right now , the page is only submitting to itself. And the bean class is used to instantiate the passed values into a bean .Am i missing something that you are trying to say ?.Thanks for replying
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

okay, in that case which values exactly (from the below page) are you not getting ?
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Robin John wrote:okay, in that case which values exactly (from the below page) are you not getting ?

Im not being able to get the values of properties statusActive and statusEdit , these properties correspond to checkbox values.
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

try checking the value which you are submitting

<INPUT TYPE="CHECKBOX" NAME="statusActive" onclick="alert(this.value);"/>

and just a warning: stop using Java scriptlets inside jsp page use el / ognl libraries instead...
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Robin John wrote:try checking the value which you are submitting

<INPUT TYPE="CHECKBOX" NAME="statusActive" onclick="alert(this.value);"/>

and just a warning: stop using Java scriptlets inside jsp page use el / ognl libraries instead...


Thanks for replying . I did check the value being passed , and it shows as 'on' when clicked which reflects the logic however , this value is not being reflected into the bean , why is that?
EDIT:Also , Im very new to programming and hence i'm using java scriptlets as i do not know how to use EL tags.Hope you understand
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

well you can have a single value in the "name" attribute and multiple values of the "value" attribute of the checkbox as they are used in groups... usually a string array in the name should do..
By default, the checkbox is initially off. If you want the checkbox initially on, use the CHECKED attribute.
for example:



Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Robin John wrote:well you can have a single value in the "name" attribute and multiple values of the "value" attribute of the checkbox as they are used in groups... usually a string array in the name should do..
By default, the checkbox is initially off. If you want the checkbox initially on, use the CHECKED attribute.
for example:





Hi Robin,
Thanks for replying . I understand that when a checkbox is unchecked it returns null and when checked it returns the value in the VALUE attribute .However I dont know how far your advice would help me . Here , all im doing is getting the value from the jsp and trying to store it in the bean ,whose value im trying to access by using the getProperty tag , im baffled as to why that returns null
As a result of your suggestion i did try the following

However the bean does not display the value "1" upon being checked .
Could you or anyone please point out , what I'm missing here .
Thank you for your patience.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checkbox value not being passed to bean.
 
Similar Threads
Jstl not reflecting values back to servlet
Comparing values using JSTL
Inserting a checkbox value into database.
Cannot find any information on property in a bean of type
Retaining drop down values on page submit