JSF Property not readable on type booleanrefactoring an application, I decided to convert a
booleanproperty mapped on a JSF UI radio button from a pure boolean to a three state choice:
How hard can it be?
Depending on the Tomcat you are using, it can be surprisingly hard. In fact, passing a
nullto a primitive boolean value is wrong in Java, because autoboxing works only from objects to primitives, not viceversa.
So the solution seems to be to convert your primitive type to an object one, that is a
Boolean, but in doing so, Java keeps things hard introducing again the awkward Java Beans specification. Therefore, if you had
public boolean isFoo()method, converting it to
public Boolean isFoo()method will raise an exception that tells you the property
foois not readable.
Foonow an object, it must be accessed with
SummaryWhen dealing with Java objects that represent primitive boolean types, having the
ismethod prefix is totally wrong.
And it does not matter how ugly it is to have your Java code to be less readable, after all how ugly it is something like:
if( isDebugEnabled() ) logger.debug( "Something" );
with respect to the horrible Java Beans one that follows?
if( getDebugEnabled() ) logger.debug( "Something" );
One bovine solution could be to implement both
getaccessor with one relying on the other, but are you sure this will not produce confusion when dealing with code assistant during your daily development?