File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes actionlistener for selectBooleanCheckbox doubt? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "actionlistener for selectBooleanCheckbox doubt?" Watch "actionlistener for selectBooleanCheckbox doubt?" New topic
Author

actionlistener for selectBooleanCheckbox doubt?

Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
I have a doubt. I have a textbox and checkbox in my jsp page. I want to write a action listener to my check box. If I uncheck my checkbox of type selectBooleanCheckbox, then I want to disble the textbox so that the usercan't input into the textbox and if the user checks on the checkbox, then I want to able the textbox with some initial values. Is it possible to do like this for selectBooleanCheckbox type? please let me know.

Regards
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
No need for an actionlistener. Just submit the form onclick and use the checkbox value in the disabled attribute.

JSF

MyBean
[ August 27, 2008: Message edited by: Bauke Scholtz ]
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Thanks Bauke. It works. Suppose, if I want to display the status of the checkbox as true or false, how do I do that.
I tried as below:



But it prints as below:


basically .toString doesn't convert it into true or false. Please let me know. Thanks.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Use UIInput#getValue(). Using Object#toString() just returns the classname and hashcode, you should know that better. Always read the API documentation before asking this kind of trival questions: http://java.sun.com/javaee/5/docs/api/javax/faces/component/html/HtmlSelectBooleanCheckbox.html

You can also add a valuebinding to it, e.g. value="#{myBean.status}" which maps to a boolean property. But don't use it in the disabled attribute, it won't work due to the timing in the JSF lifecycle when the property value is get/set.
[ August 28, 2008: Message edited by: Bauke Scholtz ]
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Hi Thanks for your response.

When I try to change the checkbox status and then submit the form, basically calling another page through a java method, I am not able to navigate to the next page.

Where as I am able to navigate without changing the checkbox status? Why is it so? How to rectify?

Page1 gets the user input and page2 just displays the user. I am able to display the user input into second page if I don't alter the checkbox status. But if I change the checkbox status, if I press submit button on the first page, it is not navigating to the second page. Can anyone tell me why? This is just a simple example I have started playing around with jsf. But I think when the page gets refreshed when I change the checkbox, something happens which prevents from navigating. As a beginner, I am not able to overcome this problem. Please let me know.

page1.jsp



page2.jsp


UserBean.java


And more over I am trying to clear the text box to null if checkbox is Where should I mention?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: actionlistener for selectBooleanCheckbox doubt?