| Author |
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
Bartender
Joined: Jul 06, 2005
Posts: 1008
|
|
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: org.apache.taglibs.standard.lang.support The struts-el tags use that. Good luck, evnafets
|
 |
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
Marshal
Joined: Jan 10, 2002
Posts: 56544
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: Add el support to your own taglib
|
|
|