Accessing method from JSTL
just was wondering if there is a way to access a method from my class without creating a custom taglib.
Example I got a class which provides 4 methods: hasDisplay(), hasCreate(), hasDelete() and hasEdit() - all of them just returning a boolean value.
From my jsp I just want to
<c:if test="{ar.hasEdit}"></c:if>
But this on开发者_开发百科ly works with getter and setter methods, am I right?
If you don't want to write your own tags you could provide a decorator for the object that provides a "beanish" interface. So you wrap hasedit() with isHasEdit() that way cou can keep your jsps clean and still use the desired syntax, but you end up with "dirty" wrappers.
I'd go for a custom taglib. It's not that complicated.
Correct, JSP EL can only access bean properties. Anything else needs a custom taglib. It's not good enough, but there it is.
精彩评论