File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
    Bookmark Topic Watch Topic
  • New Topic
 
friki data migration
Ranch Hand
Posts: 772
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Under JSP 2.0 you can define functions that can be referenced from within EL expressions. For full details, please see section JSP.2.6 in the JSP 2.0 Specification: http://jcp.org/aboutJava/communityprocess/final/jsr152/

Let's say that you want to use some static functions such as those defined by the Jakata Commons StringEscapeUtils class (http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/StringEscapeUtils.html) from within your EL expressions. In particular, let's pick the escapeJavaScript method whose signature is:



In order to define an EL function, a <function> element must be added to an existing or new TLD file that is in the scope of your application and declared within the referencing JSP page. For our example, if we wanted to name the EL function the same name as the static method (though they do not need to be the same), we could add:



to a TLD file in our web application. (Of course, this class must be available in the classpath of the web app).

Note that the class name of the enclosing class must be fully qualified, and note that the class names in the signature must also be fully qualified.

On a JSP page where you wish to reference your new EL function, you would declare the taglib as any other. For example:



and then you could use the function in any EL expression on that page. Be sure that the uri value matches the URI defined within your TLD file. For example:



Let's say that we have a scoped variable named someText that contains text that we want to emit into the context of a JavaS'cript string. In order to make sure that there will be no quoting problems, we want to call our escape function on the string so that any embedded quotes will be escaped and will not interfere with the syntax of the JavaS'cript notation on the page.

So:



Cool stuff, no?

A fully worked example of defining and using an EL function can be found at http://www.orionserver.com/docs/tutorials/taglibs/18.html


JspFaq
 
I agree. Here's the link: http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic