File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Disabled checkbox problem. 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 » Frameworks » Struts
Bookmark "Disabled checkbox problem." Watch "Disabled checkbox problem." New topic
Author

Disabled checkbox problem.

omkar patkar
Ranch Hand

Joined: Aug 25, 2005
Posts: 231
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.


Thanks and Regards
Omkar Patkar (SCJP 1.4)[url]http://javacollectionsnotes.blogspot.com[/url] | [url]http://omkar-myscjpexp.blogspot.com[/url]
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
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

Joined: Aug 25, 2005
Posts: 231
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

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
omkar patkar
Ranch Hand

Joined: Aug 25, 2005
Posts: 231
Thanks Merill and Dom, .... The hidden field method is working !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Disabled checkbox problem.
 
Similar Threads
retaining checkbox value
checkbox must always be checkd
checkbox-once clicked-always sends the value as true
Capturing Checkbox value using spring framework
html:checkbox disable property