I'm migrating an old application from JSP 1.1 to JSP 2.1, and trying to do everything without scriptlets. I have a JavaBean that I create, populate and insert into the page scope via a CustomTag. This JavaBean exposes some methods that transform data, generate HTML snippets, etc, based on it's instance variables.
When I need to access a property in the JavaBean I use:
${mybean.property}
But since JSP 2.1/EL 2.1 don't support calling methods on your beans (this requires JSP 2.2/EL 2.2), I'm trying to determine the best way to expose such utility methods to my JSP pages without resorting to scriptlets.
Here is an example of the methods on the JavaBean that I need to access:
public String getThumbColor() {
String tbgcolor = "#FF0000";
if (this.getJavaBuildTotal() > 0 &&
this.getJavaBuildBroke() == 0 &&
this.getCeeBuildBroke() == 0 &&
this.getJavaBuildInvalid() == 0 &&
!this.hasBuildException()) {
tbgcolor = "#00FF00";
}
else if (this.getJavaBuildTotal() == 0 && this.getCeeBuildTotal() == 0) {
tbgcolor = "#f7f814";
}
return tbgcolor;
}
It feels like converting this (and the 10 or so other methods like it) entirely to JSTL in the JSP would be muddying up my JSP page.
Since I'm already doing a large refactoring, I don't mind drastic changes; yet I can't think of anyway to eliminate my need of certain methods that use conditionals for deciding on return values, generate small HTML snippets, etc.