Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

h:selectBooleanCheckbox  RSS feed

 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a field in the db - Use for Forecast. This field is of char(1) datatype. Ie it returns a 'Y' or an 'N'.

This field in the UI is represented as a checkbox.

When this field returns 'Y', in the UI , i want the corresponding checkbox to be checked. How do I render this? Any ideas? I am using the DAO pattern along with JSF for the front end with WSAD 5.1.2 as IDE and websphere 5.1 as app server.
 
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just not to sound rude, you are asking us to code for you.
I would really love to help if I am getting paid though..


When this field returns 'Y', in the UI , i want the corresponding checkbox to be checked.



Note that the above code has not been tested. This code is to just give you a general idea.
 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your solution did work. But I have a problem.

As suggested, I have a set and get method in the bean for conversion from string to boolean and vice versa. However, when i say


it gets rendered properly when i load the form with data retrieved from db. If I render the same page for creating a new record, it gives me the foll exception as follows:

Caused by: javax.faces.el.EvaluationException: Error getting property 'useForForecastBoolean' from bean of type com.nwa.dymond.parm.holidayFcst.HolidayFcstParmModel: java.lang.NullPointerException
at com.sun.faces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java(Compiled Code))
at com.ibm.faces.databind.SelectItemsPropResolver.getValue(SelectItemsPropResolver.java(Compiled Code))
at com.ibm.faces.sdo.SdoPropertyResolver.getValue(SdoPropertyResolver.java(Compiled Code))
at com.ibm.faces.application.SuperPropertyResolver.getValue(SuperPropertyResolver.java(Compiled Code))
at com.sun.faces.el.impl.ArraySuffix.evaluate(ArraySuffix.java(Compiled Code))
at com.sun.faces.el.impl.ComplexValue.evaluate(ComplexValue.java(Compiled Code))
at com.sun.faces.el.impl.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:238)
at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:155)
... 58 more

Caused by: java.lang.NullPointerException
at com.nwa.dymond.parm.holidayFcst.HolidayFcstParmModel.getUseForForecastBoolean(HolidayFcstParmModel.java:166)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
... 66 more



My bean definitions are as follows:

 
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code checking for null is wrong.
It should have been

if(useForForecast!= null)

instead of

if(!useForForecast.equalsIgnoreCase(null)

All the references of the "null" comparisons should be changed to the above.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!