tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pierre Delisle <Pierre.Deli...@Sun.COM>
Subject Re: how to use methods with parameters
Date Thu, 05 Feb 2004 18:22:05 GMT

> is it possible to use JSTL for an expression like
>  
> <%=calculateDays(startDate, endDate) %> ???
>  
>  
> probably not, but I am too new to JSTL to figure it out by myself. Could
> someone advise me?

This could be possible through an EL function (introduced in JSP 2.0).
The syntax would be as follows:

  ${acme:calculateDays(startDate, endDate)}

You'd have to define in one of your classes a static method "calculateDays" with the proper
signature (Date, Date). The name, class, and signature would then have to be defined
within a <function> element in a TLD.

Here is a snapshot of 'fn.tld' for the standardized functions 
in JSTL 1.1:

---
<?xml version="1.0" encoding="UTF-8" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
  version="2.0">
    
  <description>JSTL 1.1 functions library</description>
  <display-name>JSTL functions</display-name>
  <tlib-version>1.1</tlib-version>
  <short-name>fn</short-name>
  <uri>http://java.sun.com/jsp/jstl/functions</uri>

  <function>
    <description>
      Tests if an input string contains the specified substring.
    </description>
    <name>contains</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>boolean contains(java.lang.String, java.lang.String)</function-signature>
    <example>
      &lt;c:if test="${fn:contains(name, searchString)}">
    </example>
  </function>
  ...
---

    -- Pierre


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message