Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Disabled checkbox problem.

 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I have got a different problem. I have a checkbox which,... depending upon certain condition it is either disabled or its not disabled. However according to the requirement i want to send the value of a boolean property in form bean associated with this checkbox. Currently, i get "false" value. But, that should not be the case. For e.g. If the checkbox is "CHECKED" and its disabled, then i must be able to send "true" to database. and if the checkbox is "NOT CHECKED", and its disabled then i must be able to send "false" to the database. In other words, its just for the user to know that the checkbox is a readonly field. However, if the checkbox is not disabled, then its usual, behavior must take place. How do i do that ? ...I am using struts 1.2.8. Merill any idea ?

Thanks and regards
Omkar Patkar.
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Disabled form elements are not submitted with the form. You'll probably have to use a hidden field to keep track of the checkbox's status.
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dom,
Thanks Man ! Ok then lets say, i have 4 fields in my form :-

1) First Name (textbox)
2) Second Name (textbox)
3) Mobile (textbox)
4) Is Admin ? (checkbox)


So my form fields will also contain four properties....right ? Now, if i keep a hidden field in the form (i.e., 5th field) then i will have to access the value of hidden field as if i was accessing the value of the check box. .... i hope i am correct ! But, that will be working perfectly well, if my checkbox is always disabled. In my application, the checkbox is conditionally disabled ...i.e., READONLY, depending upon rights of the logged in user. When the checkbox is not disabled, then it is made editable to user. So if user "CHECKs" the checkbox then "true" must be sent. On the other hand, when user unchecks the checkbox, then "false" must be sent to the database. ... Now how this can be achieved using that hidden field ?

Thanks and Regards
Omkar Patkar.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wrap your <html:hidden> tag inside a <logic:equal> tag based on the same condition that determines whether or not the checkbox is disabled. That way the hidden field will be rendered only if the checkbox is disabled. Otherwise, only the checkbox will be rendered, and it will function normally.
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Merill and Dom, .... The hidden field method is working !
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic