|Home > Guides > Tag Developers Guide > JSP > Access to ValueStack from JSPs|
To access the ValueStack from third-party JSP taglibs, expose property values to JSP using the
After setting parameters, third-party JSP taglibs can access variables or use JSP 2.0 EL (Expression Language). This is convenient as short hand EL expression syntax
can be used in a text or inside of tag attributes:
In practice, several variables must be exposed to make effective use of third party taglibs like DisplayTag. Unfortunately, this approach leads to a lot of
Why can't we just replace EL with OGNL?
Unfortunately, it isn't that simple. we tinkered with
JSPFactory.setDefault() to wrap around
getPageContext() and create
ExpressionEvaluator that would use OGNL. This strategy works in practice, but code generated by Jasper2 doesn't call
JSPFactory.getPageContext().getExpressionEvaluator() but goes directly to static method that is hardwired to Jakarta Commons-EL implementation.
Even if this approach did work, it wouldn't be clean as
JSPFactory.setDefault() should only be called by JSP implementation.
There is a simple, if not elegant, solution available in JSP 2.0 EL, for exposing ValueStack to OGNL. It is possible to create custom functions that can be called from EL expressions. Functions have to be 'public static' and specified in a TLD file.
To use a function, import the TLD in a JSP file where you've want to use a function. For example, you could access Action properties by evaluating OGNL expression by a function 'vs' (for valuestack) in EL.
To use this code you've got to add
Functions.java to your webapp project.
If someone were interested, it would be helpful for a developer (like you!) to define a set of functions that we could include in a future release of the framework.