TOP RSS LOGIN

Community

Product

Contact

Please send mail to takezoe@aa.bb-east.ne.jp.

SourceForge.jp

Java Standard EL Functions

Java Standard EL Functions(JSEL) provides standard EL functions for web application development.

Download

Source code is available on Subversion repository on SourceForge.jp. You can browse it using web browser at the following URL:

Subversion repository URL is:

License

Apache License, Version 2.0

How to Use

 Setup

Put functions-x.x.x.jar into WEB-INF/lib and add following filter definition to your web.xml.

<filter>
  <filter-name>functionsFilter</filter-name>
  <filter-class>jp.sf.amateras.functions.filter.FunctionsFilter</filter-class>
</filter>

<filter-mapping>
  <filter-name>functionsFilter</filter-name>
  <url-pattern>*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
</filter-mapping>

Add the following taglib directive to your JSP:

<%@ taglib uri="http://amateras.sf.jp/functions" prefix="f" %>
<%@ taglib uri="http://amateras.sf.jp/log4j" prefix="log" %>

You can use EL functions which provided by JSEL:

${f:h(bean.property)}

 Functions

A table of available EL functions are here:

Core Functions (http://amateras.sf.jp/functions)

Function Description
f:h(String value) Escape HTML tags
f:u(String value) URL encode
f:br(String value) Convert line separator to <br>
f:nbsp(String value) Convert space to &nbsp;
f:cut(String value, int length)
f:link(String value) Convert URL to link
f:mask(String value) Convert String to astarisk
f:date(Date date) Format Date using date pattern
f:datetime(Date date) Format Date using datetime pattern
f:time(Date date) Format Date using time pattern
f:number(Object number, String pattern) Format number using given pattern
f:json(Object bean) Cpnvert object to JSON
f:query(Object params) Assemble query string from map's key and value
f:matches(String value, String pattern) Test whether value matches regex pattern
f:replace(String value, String pattern, String replacement) replace regex pattern in value with replacement
f:js(String value)
f:concat(Object value1, Object value2 Join value1 and value2
f:contains(Object value1, Object value2) Test whether value1 contains value2

Log Functions (http://amateras.sf.jp/log4j)

Function Description
log:trace(Object message) Output log as TRACE level
log:debug(Object message) Output log as DEBUG level
log:info(Object message) Output log as INFO level
log:warn(Object message) Output log as WARN level
log:error(Object message) Output log as ERROR level
log:fatal(Object message) Output log as FATAL level
log:printTrace(Object message) Displays message if TRACE log is enabled
log:printDebug(Object message) Displays message if DEBUG log is enabled
log:printInfo(Object message) Displays message if INFO log is enabled
log:printWarn(Object message) Displays message if WARN log is enabled
log:printError(Object message) Displays message if ERROR log is enabled
log:printFatal(Object message) Displays message if FATAL log is enabled
log:isTraceEnabled() Tests whether TRACE log is enabled
log:isDebugEnabled() Tests whether DEBUG log is enabled
log:isInfoEnnabled() Tests whether INFO log is enabled
log:isWarnEnabled() Tests whether WARN log is enabled
log:isErrorEnabled() Tests whether ERROR log is enabled
log:isFatalEnabled() Tests whether FATAL log is enabled

These functions output log using Log4j. Logger name is decided by the following rules.

  • Gets servlet path using HttpServletRequest#getServletPath()
  • Removes the first / and the last .jsp from servlet path
  • Replaces / to . in jsp.<servlet path> and it would be a logger name

For example, /index.jsp is jsp.index, /admin/index.jsp is jsp.admin.index. Define appenders which are applied to these loggers in your log4j.properties or log4j.xml.

 Configuration

Some EL functions such as f:date()、f:datetime()、f:time() have default format pattern. If you want to customize these patterns, create and put functions.properties into classpath root as the following contents.

# Charset of URL encoding which used by f:u()
defaultEncoding=UTF-8

# Format pattern of f:date()
datePattern=yyyy/MM/dd

# Format pattern of f:datetime()
datetimePattern=yyyy/MM/dd HH:mm:ss

# Format pattern of f:time()
timePattern=HH:mm:ss

Default functions.properties is contained by functions-x.x.x.jar.

 Maven

You can get JSEL from Maven repository which is provided by Project Amateras. Add the following fragment to your pom.xml.

<repositories>
  <repository>
    <id>amateras</id>
    <name>Project AMateras Maven2 Repository</name>
    <url>http://amateras.sourceforge.jp/mvn/</url>
  </repository>
</repositories>
...
<dependencies>
  <dependency>
    <groupId>jp.sf.amateras.functions</groupId>
    <artifactId>functions</artifactId>
    <version>1.1.2</version>
  </dependency>
</dependencies>

History

 1.1.2 - 2011/01/19

  • f:contains() supports Array.
  • Fixed a problem of functions.tld.

 1.1.1 - 2010/09/30

  • Add functions to print message to JSP by log level such as log:printTrace().
  • Add functions to test whether log level is enabled such as log:isTraceEnabled().

 1.1.0 - 2010/03/16

  • Add FunctionsFilter. This filter is required to use a part of JSEL features.
  • Add f:json()、f:query()、f:matches()、f:replace()、f:js()、f:concat()、f:contains().
  • Add Log4j functions such as log:trace().
  • Add $context variable which available on JSP

 1.0.0 - 2010/01/30

Initial Release.