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!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Configure EL function in tag library descriptor?

 
vishwa venkat
Ranch Hand
Posts: 185
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can some one explanisn how to do configuring EL function in tag library descriptor?Please give an example showing how to use thius function also,
Thanks
 
Dimple Kaushik
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Online resources
Expression Language Functions:
When the EL moved from the JSTL specification to the JSP specification, it picked up a new trick: namely, how to invoke functions. The EL function syntax is simple: the function name, followed by a list of arguments within parenthesis:
<%@ taglib prefix="fn"
uri="http://java.sun.com/jsp/jstl/functions" %>
${fn:length(myCollection)}

A function belongs to a tag library and the function name includes the prefix assigned to the library with the taglib directive in the page. In this example, I use the prefix fn, which is the default prefix for the JSTL function library.
The Tag Library Descriptor (TLD) maps the function name to a static method in a Java class that implements the functionality:

<function>
<description>
Returns the number of items in a collection or the number of
characters in a string.
</description>
<name>length</name>
<function-class>
org.apache.taglibs.standard.functions.Functions
</function-class>
<function-signature>
int length(java.lang.Object)
</function-signature>
</function>

The most interesting element here is the <function-signature> element. It contains a declaration of the type of value the function returns, the name of the static implementation method, and type declarations for all arguments (zero or more, comma-separated) within parenthesis. The return type and the argument types must be either Java primitive types or fully qualified type names.
The static method for the length() function is implemented like this in the Jakarta Taglibs Standard library:

public static int length(Object obj)
throws JspTagException {
if (obj == null)
return 0;
if (obj instanceof String)
return ((String)obj).length();
if (obj instanceof Collection)
return ((Collection)obj).size();
if (obj instanceof Map)
return ((Map)obj).size();
int count = 0;
if (obj instanceof Iterator) {
Iterator iter = (Iterator) obj;
count = 0;
while (iter.hasNext()) {
count++;
iter.next();
}
return count;
}
if (obj instanceof Enumeration) {
Enumeration enum = (Enumeration) obj;
count = 0;
while (enum.hasMoreElements()) {
count++;
enum.nextElement();
}
return count;
}
try {
count = Array.getLength(obj);
return count;
} catch (IllegalArgumentException ex) {}
throw new JspTagException("Unsupported type"));
}

As you see, there's nothing strange going on here. It's a regular static method that finds out the length its argument using an approach suitable to the specific runtime type of the argument.
Hope this helps.
[ February 02, 2004: Message edited by: Dimple Kaushik ]
[ February 02, 2004: Message edited by: Dimple Kaushik ]
 
Sumit Amar
Ranch Hand
Posts: 180
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good example, thanks.
 
Ali Ragi
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dimple Kaushik,
Your comments is a great help, thanks!
One more question: As far as I know, EL can only use those static functions, which being developed for the EL used. I am wondering whether EL can use or call other class object's static and instance method on the fly, like the length()in String class? Thanks in advance!
 
vishwa venkat
Ranch Hand
Posts: 185
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot..
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic