Bookmark Topic Watch Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis
  • 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:

Let's say that you want to use some static functions such as those defined by the Jakata Commons StringEscapeUtils class ( 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.


Cool stuff, no?

Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!