Wednesday, December 16, 2009

Say Hello to EL Functions

EL functions allows you to call a java function from your JSP pages with out using any scripltes(in your JSP).It really important to have a scriplets free JSP pages, which make developer and designer life easy.Below is a simple example of using EL function.

Simple Java Class with Static Method:

* Before calling a method from your JSP page, the method should be public and static.
*
Below is the code where we defined a class called SimpleELFunctions and static method called sayHello
package com.passion4java.el.functions;
public class SimpleELFunctions {

 public static String sayHello(String test){
  return "Say HELLO Hello EL Function";
 }
}

TLD files with function tags

*
below is a simple tld where we have to defined the Class name in function-class tag and  the method signature in function-signature tag.

 1.0
 elfunctions
 
  sayHello
  com.passion4java.el.functions.SimpleELFunctions
  java.lang.String sayHello(java.lang.String)
 


JSP Page

*
add your tld file uri to @taglib directive and give the prefix name to it. in our example its p4j
*
When you are calling EL function  first  we have give the prefix name p4j and a :(colon)
* then call the name which  is defined in the tld file under  name tag ending with a () (open and close bracket)
<%@ taglib prefix="p4j" uri="elfunctions" %>
< html >
  < head >
    
    < title >Say Hello< /title >
  < /head >
  < body >
    ${p4j:sayHello("test")}
  < /body >
< /html >


Thats it.. ;)

1 comment:

Post a Comment

 

This content comes from a hidden element on this page.

The inline option preserves bound JavaScript events and changes, and it puts the content back where it came from when it is closed.
Click me, it will be preserved!

If you try to open a new ColorBox while it is already open, it will update itself with the new content.

Updating Content Example:
Click here to load new content