Skip to main content


Showing posts from October, 2011

Do 'is' boolean methods work in JSPs with JSTL?

When coding in JSTL you often want to use conditional logic (I'm thinking and the like) to be able to structure your page correctly. Auto-generated getter & setter methods will normally create isX() methods for the getters of boolean values (at least in Eclipse it does) but can you access this method directly from JSTL without writing a getX() version?

Does JSTL support 'is' boolean methods though? Ask a random poll of Java we developers and you will get conflicting answers so I decided to investigate, want the short answer?

YES - JSTL does support accessing isX() methods directly as if you were accessing a getX() method, but only if the return type of the isX() method is a primative boolean. If you return an object of any kind (such as Boolean isObjectBooleanTrue()) then JSTL fails to find the method and will give you a rather nasty JSP exception:
javax.el.PropertyNotFoundException: The class 'com.andrewbeacock.BooleanTest' does not have the property 'obj…

How to stop Eclipse reformating your Java enumerations & comments

Eclipse is a wonderful IDE for the Java language and I’ve used it daily for at least the past 4 years but it does have some 'issues'. One is regarding it’s code formatting (or reformatting) support, normally it does a great job of putting stuff in the right place but there are occasions where it just fails to get it right.

When I write enums I like to have each item on it's own row, I find it's easier to read and amend in the future:
public enum Family { MOTHER, FATHER, DAUGHTER, SON; } But Eclipse has other ideas and formats it so that it looks like this:
public enum Family { MOTHER, FATHER, DAUGHTER, SON; } A way to get around this (and any other times where you have a few lines of code that you don't want collapsing into one is to add the double-slash style code comments to the end of each line:
public enum Family { MOTHER, // FATHER, // DAUGHTER, // SON; } Block comments

I recently wanted to have a decent sized chun…