org.omnifaces.taghandler
Class ImportFunctions

java.lang.Object
  extended by javax.faces.view.facelets.TagHandler
      extended by org.omnifaces.taghandler.ImportFunctions
All Implemented Interfaces:
javax.faces.view.facelets.FaceletHandler

public class ImportFunctions
extends javax.faces.view.facelets.TagHandler

The <o:importFunctions> allows the developer to have access to all functions of the given fully qualified name of a type in the EL scope using the usual EL functions syntax without the need to register them in .taglib.xml file. The functions are those public static methods with a non-void return type. For example:

 <o:importFunctions type="java.lang.Math" var="m" />
 <o:importFunctions type="org.omnifaces.util.Faces" />
 ...
 #{m:abs(-10)}
 #{m:max(bean.number1, bean.number2)}
 ...
 <base href="#{Faces:getRequestBaseURL()}" />
 

The functions prefix becomes by default the simple name of the type. You can override this by explicitly specifying the var attribute. If there are multiple function methods with exactly the same name, then the one with the least amount of parameters will be used. If there are multiple function methods with exactly the same name and amount of parameters, then the choice is unspecified (technically, JVM-dependent) and should not be relied upon. So if you absolutely need to differentiate functions in such case, give them each a different name.

Note that the colon : operator to invoke the method is as required by EL functions spec. It's by design not easily possible to change it to the period . operator. Also note that in case of org.omnifaces.util.Faces it's considered poor practice if the same functionality is already available through the implicit EL variables #{facesContext}, #{view}, #{request}, etc such as #{request.contextPath} which should be preferred over #{Faces:getRequestContextPath()}.

The resolved functions are by reference stored in the cache to improve retrieving performance.

Since:
1.4
Author:
Bauke Scholtz

Field Summary
 
Fields inherited from class javax.faces.view.facelets.TagHandler
nextHandler, tag, tagId
 
Constructor Summary
ImportFunctions(javax.faces.view.facelets.TagConfig config)
          The tag constructor.
 
Method Summary
 void apply(javax.faces.view.facelets.FaceletContext context, javax.faces.component.UIComponent parent)
          Register a new FunctionMapper which checks if the given prefix matches our own var and then find the associated method based on the given method name.
 
Methods inherited from class javax.faces.view.facelets.TagHandler
getAttribute, getRequiredAttribute, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ImportFunctions

public ImportFunctions(javax.faces.view.facelets.TagConfig config)
The tag constructor.

Parameters:
config - The tag config.
Method Detail

apply

public void apply(javax.faces.view.facelets.FaceletContext context,
                  javax.faces.component.UIComponent parent)
           throws java.io.IOException
Register a new FunctionMapper which checks if the given prefix matches our own var and then find the associated method based on the given method name.

Throws:
java.io.IOException