tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Schneider <k...@dotech.com>
Subject RE: How to access java object method from JSTL expression
Date Wed, 08 Sep 2004 18:37:57 GMT
Nope, there's nothing really directly available in JSTL 1.0/JSP 1.2 (outside of
using scripting expressions) to do the same thing as JSP 2.0 EL functions. I'm
in the process of building something that may help however. The Standard 1.1
implementation includes the org.apache.taglibs.standard.functions.Functions
class. Basically, this is a utility class that contains the static methods used
for the JSTL 1.1 functions. In a similar manner, I've got my own Functions
class that includes a couple of simple methods:

import java.beans.Expression;
import java.beans.Statement;
..
public class Functions {

    public static void statement(Object target, String methodName, Object[]
args) throws Exception {
        Statement stmt = new Statement(target, methodName, args);
        stmt.execute();
    }

    public static Object expression(Object target, String methodName, Object[]
args) throws Exception {
        Expression expr = new Expression(target, methodName, args);
        return expr.getValue();
    }
    ...
}

Not very impressive, eh? But they're actually quite powerful. Give the JavaDocs
a look:

http://java.sun.com/j2se/1.4.2/docs/api/java/beans/Statement.html
http://java.sun.com/j2se/1.4.2/docs/api/java/beans/Expression.html

Combined with some information found here:

http://www.onjava.com/pub/a/onjava/2002/10/30/jstl3.html

It's not too hard to come up with statement and expression tags that are
EL-enabled for JSP 1.2. When I'm able to move to JSP 2.0, those static methods
will come along for the ride and can be made available through EL functions
instead.

Quoting Helen Ge <hge@mamsi.com>:

> 
> I am using JSTL 1.0(JSP 1.2) now. 
> 
> The java class method I am trying to access is a static method. 
> I saw JSP 2.0 added the ability to call public static methods in EL
> expressions by adding a function element to our tag library descriptor
> (TLD). does JSP 1.2 has anyway to do that?
> 
> Also, what if the method is not static method and the object is a not a bean
> , how to access that method?
> 
> 
> 
> -----Original Message-----
> From: Kris Schneider [mailto:kris@dotech.com] 
> Sent: Wednesday, September 08, 2004 12:57 PM
> To: Tag Libraries Users List
> Subject: Re: How to access java object method from JSTL expression 
> 
> Are you using JSTL 1.0 (JSP 1.2) or JSTL 1.1 (JSP 2.0)?
> 
> Quoting Helen Ge <hge@mamsi.com>:
> 
> > Hi,
> > 
> >  
> > 
> > I saw some examples to access standard java bean properties from JSTL
> > expression language on JSP page. I am wondering is there any way to access
> > regular java class methods from JSTL expression?
> > 
> >  
> > 
> > Now in the JSP, I am trying to access a Java class, which has a business
> > method return a string value. That java class is not a java bean class.
> Can
> > someone tell me how to do that?
> > 
> >  
> > 
> >  
> > 
> > Thanks
> 
> -- 
> Kris Schneider <mailto:kris@dotech.com>
> D.O.Tech       <http://www.dotech.com/>

-- 
Kris Schneider <mailto:kris@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message