Class UIImportConstants
- java.lang.Object
-
- jakarta.faces.component.UIComponent
-
- jakarta.faces.component.UIComponentBase
-
- jakarta.faces.component.UIImportConstants
-
- All Implemented Interfaces:
PartialStateHolder
,StateHolder
,TransientStateHolder
,ComponentSystemEventListener
,FacesListener
,SystemEventListenerHolder
,EventListener
public class UIImportConstants extends UIComponentBase
UIImportConstants imports a mapping of all constant field values of the given type in the current view.
The
ViewDeclarationLanguage
implementation must cause an instance of this component to be placed in the view for each occurrence of an<f:importConstants />
element placed inside of an<f:metadata />
element. The user must place<f:metadata />
as a direct child of theUIViewRoot
. TheViewMetadata.createMetadataView(jakarta.faces.context.FacesContext)
must take care of actual task of importing the constants.Instances of this class participate in the regular Jakarta Faces lifecycle, including on Ajax requests.
The purpose of this component is to provide a mapping of all constant field values of the given type in the current view. Constant field values are all
public static final
fields of the given type. The map key represents the constant field name asString
. The map value represents the actual constant field value. This works for classes, interfaces and enums.Usage
The below constant fields:
package com.example; public class Foo { public static final String FOO1 = "foo1"; public static final String FOO2 = "foo2"; }
package com.example; public interface Bar { public static final String BAR1 = "bar1"; public static final String BAR2 = "bar2"; }
package com.example; public enum Baz { BAZ1, BAZ2; }
Can be imported as below:
<f:metadata> <f:importConstants type="com.example.Foo" /> <f:importConstants type="com.example.Bar" var="Barrr" /> <f:importConstants type="com.example.Baz" /> </f:metadata>
And can be referenced as below:
#{Foo.FOO1}, #{Foo.FOO2}, #{Barrr.BAR1}, #{Barrr.BAR2}, #{Baz.BAZ1}, #{Baz.BAZ2}
<h:selectOneMenu value="#{bean.baz}" > <f:selectItems value="#{Baz}" /> </h:selectOneMenu>
- Since:
- 2.3
-
-
Field Summary
Fields Modifier and Type Field Description static String
COMPONENT_FAMILY
The standard component family for this component.static String
COMPONENT_TYPE
The standard component type for this component.-
Fields inherited from class jakarta.faces.component.UIComponent
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, FACETS_KEY, VIEW_LOCATION_KEY
-
-
Constructor Summary
Constructors Constructor Description UIImportConstants()
Create a newUIImportConstants
instance with renderer type set tonull
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getFamily()
Return the identifier of the component family to which this component belongs.String
getType()
Returns the fully qualified name of the type to import the constant field values for.String
getVar()
Returns name of request scope attribute under which constants will be exposed as a Map.void
setType(String type)
Sets the fully qualified name of the type to import the constant field values for.void
setValueExpression(String name, ValueExpression binding)
Set theValueExpression
used to calculate the value for the specified attribute or property name, if any.void
setVar(String var)
Sets name of request scope attribute under which constants will be exposed as a Map.-
Methods inherited from class jakarta.faces.component.UIComponentBase
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeBegin, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getRendersChildren, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, subscribeToEvent, unsubscribeFromEvent
-
Methods inherited from class jakarta.faces.component.UIComponent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, visitTree
-
-
-
-
Field Detail
-
COMPONENT_TYPE
public static final String COMPONENT_TYPE
The standard component type for this component.
- See Also:
- Constant Field Values
-
COMPONENT_FAMILY
public static final String COMPONENT_FAMILY
The standard component family for this component.
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UIImportConstants
public UIImportConstants()
Create a new
UIImportConstants
instance with renderer type set tonull
.
-
-
Method Detail
-
getFamily
public String getFamily()
Description copied from class:UIComponent
Return the identifier of the component family to which this component belongs. This identifier, in conjunction with the value of the
rendererType
property, may be used to select the appropriateRenderer
for this component instance. Note this method should NOT returnnull
- Specified by:
getFamily
in classUIComponent
- Returns:
- the component family (not null).
-
getType
public String getType()
Returns the fully qualified name of the type to import the constant field values for.
- Returns:
- The fully qualified name of the type to import the constant field values for.
-
setType
public void setType(String type)
Sets the fully qualified name of the type to import the constant field values for.
- Parameters:
type
- The fully qualified name of the type to import the constant field values for.
-
getVar
public String getVar()
Returns name of request scope attribute under which constants will be exposed as a Map.
- Returns:
- Name of request scope attribute under which constants will be exposed as a Map.
-
setVar
public void setVar(String var)
Sets name of request scope attribute under which constants will be exposed as a Map.
- Parameters:
var
- Name of request scope attribute under which constants will be exposed as a Map.
-
setValueExpression
public void setValueExpression(String name, ValueExpression binding)
Set the
ValueExpression
used to calculate the value for the specified attribute or property name, if any. If aValueExpression
is set for thevar
property, throw an illegal argument exception.- Overrides:
setValueExpression
in classUIComponent
- Parameters:
name
- Name of the attribute or property for which to set aValueExpression
binding
- TheValueExpression
to set, ornull
to remove any currently setValueExpression
- Throws:
IllegalArgumentException
- Ifname
is one ofid
,parent
, orvar
.NullPointerException
- Ifname
isnull
.
-
-