File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Add el support to your own taglib Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Add el support to your own taglib" Watch "Add el support to your own taglib" New topic

Add el support to your own taglib

Rusty Enisin
Ranch Hand

Joined: May 26, 2005
Posts: 107
I am working on an older app server that does not have EL support. Is there a way to add EL support to my own taglib so I can do things like this?

<my:tag value="${param.myParam}"/>

I could parse the string ( ${param.myParam} ) and then get the value. Is there a class out there that I can use that already does this?

The squeaky wheel gets the grease. Well, that or replaced...
Stefan Evans

Joined: Jul 06, 2005
Posts: 1580
Certainly there is. I've never actually done it myself, but it should be simple enough (famous last words)

There are two approaches I can think of
1 - Jakarta Commons EL implementation. This is the implementation of the JSP2.0 package javax.servlet.jsp.el. You can then use those classes in your custom tag. Use the JSP2.0 api as a source for the base classes.

2 - Look at existing source code for the JSTL, and the struts-el implementations. You should be able to leverage off of the JSTL1.0 ExpressionEvaluatorManager class. It is in the package:
The struts-el tags use that.

Good luck,
Rusty Enisin
Ranch Hand

Joined: May 26, 2005
Posts: 107
I finally got around to implementing this. Three steps to personal el bliss.

Step 1: Import these two packages from Apache:

Step 2: Each taglib has different attributes that need to ba handled differently (null, not null are the two biggies). Create a method that, for each attribute for which you want to use el, calls ExpressionUtil.evalNotNull() like this.

Step 3: Then inside the doStartTag of your taglib call the method you created above before you do anything else in the method.

Pretty snappy and works like a charm.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Rusty, this is great information for those still stuck in the JSP 1.x world (kudos to Stefan for the pointer).

I have an idea... please contact me via email.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Add el support to your own taglib
It's not a secret anymore!