• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

actionlistener for selectBooleanCheckbox doubt?

 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic