[Logo]
Forums Register Login
actionlistener for selectBooleanCheckbox doubt?
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
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 ]
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.
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 ]
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?
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards


This thread has been viewed 19910 times.

All times above are in ranch (not your local) time.
The current ranch time is
May 25, 2018 09:07:56.