tags:

views:

124

answers:

2

Hi Guys,

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?

+1  A: 

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

skaffman
+5  A: 

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.

Patrick Cornelissen
It would be great if you could write custom tags in a proper scripting language. Tagfiles are OK up to a point, but limited.
skaffman
Well I write easy tags with JSP tags and complicated ones in Java. Workds pretty good. I think that it's possible to write your tags in any jvm-language.
Patrick Cornelissen