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.. ;)

No comments:
Post a Comment