onigunn
onigunn

Reputation: 4778

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 only works with getter and setter methods, am I right?

Upvotes: 2

Views: 1868

Answers (2)

Patrick Cornelissen
Patrick Cornelissen

Reputation: 7958

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.

Upvotes: 6

skaffman
skaffman

Reputation: 403521

Correct, JSP EL can only access bean properties. Anything else needs a custom taglib. It's not good enough, but there it is.

Upvotes: 1

Related Questions