org.omnifaces.taghandler
Class ImportConstants

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

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

The <o:importConstants> allows the developer to have a mapping of all constant field values of the given fully qualified name of a type in the EL scope. The constant field values are those public static final fields. This works for classes, interfaces and enums. For example:

 public class Foo {
     public static final String FOO1 = "foo1";
     public static final String FOO2 = "foo2";
 }

 public interface Bar {
     public String BAR1 = "bar1";
     public String BAR2 = "bar2";
 }

 public enum Baz {
     BAZ1, BAZ2;
 }
 

The constant field values of the above types can be mapped into the EL scope as follows:

 <o:importConstants type="com.example.Foo" />
 <o:importConstants type="com.example.Bar" />
 <o:importConstants type="com.example.Baz" var="Bazzz" />
 ...
 #{Foo.FOO1}, #{Foo.FOO2}, #{Bar.BAR1}, #{Bar.BAR2}, #{Bazzz.BAZ1}, #{Bazzz.BAZ2}
 

The map is by default stored in the EL scope by the simple name of the type as variable name. You can override this by explicitly specifying the var attribute, as demonstrated for com.example.Baz in the above example.

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

Author:
Bauke Scholtz

Field Summary
 
Fields inherited from class javax.faces.view.facelets.TagHandler
nextHandler, tag, tagId
 
Constructor Summary
ImportConstants(javax.faces.view.facelets.TagConfig config)
          The tag constructor.
 
Method Summary
 void apply(javax.faces.view.facelets.FaceletContext context, javax.faces.component.UIComponent parent)
          First obtain the constants of the class by its fully qualified name as specified in the type attribute from the cache.
 
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

ImportConstants

public ImportConstants(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
First obtain the constants of the class by its fully qualified name as specified in the type attribute from the cache. If it hasn't been collected yet and is thus not present in the cache, then collect them and store in cache. Finally set the constants in the EL scope by the simple name of the type, or by the name as specified in the var attribute, if any.

Throws:
java.io.IOException