This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checkbox value not being passed to bean.

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bounce.Please help!
 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup if the bean class is the class to which you submit the page....
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, in that case which values exactly (from the below page) are you not getting ?
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic