Class ViewDeclarationLanguage
- Direct Known Subclasses:
ViewDeclarationLanguageWrapper
The contract that a view declaration language must implement to interact with the Jakarta Faces runtime. An implementation of this class must be thread-safe.
Instances of this class are application scoped and must be obtained from the ViewDeclarationLanguageFactory
.
- Since:
- 2.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Identifier for the Facelets view declaration language. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
buildView
(FacesContext context, UIViewRoot root) Take any actions specific to this VDL implementation to cause the argumentUIViewRoot
which must have been created via a call tocreateView(jakarta.faces.context.FacesContext, java.lang.String)
, to be populated with children.calculateResourceLibraryContracts
(FacesContext context, String viewId) Return the list of resource library contracts that will be made available for use in the view specified by the argumentviewId
.createComponent
(FacesContext context, String taglibURI, String tagName, Map<String, Object> attributes) Create a component given aViewDeclarationLanguage
specific tag library URI and tag name.abstract UIViewRoot
createView
(FacesContext context, String viewId) Create aUIViewRoot
from the VDL contained in the artifact referenced by the argumentviewId
.abstract BeanInfo
getComponentMetadata
(FacesContext context, Resource componentResource) Return a reference to the component metadata for the composite component represented by the argumentcomponentResource
, ornull
if the metadata cannot be found.getId()
Returns a non-null String that can be used to identify this view declaration language.abstract Resource
getScriptComponentResource
(FacesContext context, Resource componentResource) Take implementation specific action to discover aResource
given the argumentcomponentResource
.abstract StateManagementStrategy
getStateManagementStrategy
(FacesContext context, String viewId) For implementations that want to control the implementation of state saving and restoring, theStateManagementStrategy
allows them to do so.abstract ViewMetadata
getViewMetadata
(FacesContext context, String viewId) Return a reference to the view metadata for the view represented by the argumentviewId
, ornull
if the metadata cannot be found.getViews
(FacesContext facesContext, String path, int maxDepth, ViewVisitOption... options) Return aStream
possibly lazily populated by walking the view tree rooted at a given initial path.getViews
(FacesContext facesContext, String path, ViewVisitOption... options) Return aStream
possibly lazily populated by walking the view tree rooted at a given initial path.abstract void
renderView
(FacesContext context, UIViewRoot view) Render a view rooted at argumentview
.abstract UIViewRoot
restoreView
(FacesContext context, String viewId) Restore aUIViewRoot
from a previously created view.void
retargetAttachedObjects
(FacesContext context, UIComponent topLevelComponent, List<AttachedObjectHandler> handlers) Assuming the component metadata for argumenttopLevelComponent
has been made available by an earlier call togetComponentMetadata(jakarta.faces.context.FacesContext, jakarta.faces.application.Resource)
, leverage the component metadata for the purpose of re-targeting attached objects from the top level composite component to the individualAttachedObjectTarget
instances inside the composite component.void
retargetMethodExpressions
(FacesContext context, UIComponent topLevelComponent) Assuming the component metadata for argumenttopLevelComponent
has been made available by an earlier call togetComponentMetadata(jakarta.faces.context.FacesContext, jakarta.faces.application.Resource)
, leverage the component metadata for the purpose of re-targeting any method expressions from the top level component to the appropriate inner component.boolean
viewExists
(FacesContext context, String viewId) Tests whether a physical resource corresponding to the specified viewId exists.
-
Field Details
-
FACELETS_VIEW_DECLARATION_LANGUAGE_ID
Identifier for the Facelets view declaration language.
- Since:
- 2.1
- See Also:
-
-
Constructor Details
-
ViewDeclarationLanguage
public ViewDeclarationLanguage()
-
-
Method Details
-
restoreView
Restore a
UIViewRoot
from a previously created view. See section 7.7.2 "Default ViewDeclarationLanguage Implementation" of the Jakarta Faces Specification Document for the specification of the default implementation.- Parameters:
context
- theFacesContext
for this request.viewId
- the identifier for a previously rendered view.- Returns:
- the restored view
- Throws:
NullPointerException
- if any of the arguments arenull
-
getViewMetadata
Return a reference to the view metadata for the view represented by the argument
viewId
, ornull
if the metadata cannot be found. See section 7.7.2 "Default ViewDeclarationLanguage Implementation" of the Jakarta Faces Specification Document for the specification of the default implementation. Facelets implementation must return non-null
.- Parameters:
context
- TheFacesContext
for this request.viewId
- the view id from which to extract the metadata- Returns:
- the view metadata
- Throws:
NullPointerException
- if any of the arguments arenull
.FacesException
- if there is an error in obtaining the metadata- Since:
- 2.0
-
createView
Create a
UIViewRoot
from the VDL contained in the artifact referenced by the argumentviewId
. See section 7.7.2"Default ViewDeclarationLanguage Implementation" of the Jakarta Faces Specification Document for the specification of the default implementation.- Parameters:
context
- theFacesContext
for this request.viewId
- the identifier of an artifact that contains the VDL syntax that describes this view.- Returns:
- the newly created view root
- Throws:
NullPointerException
- if any of the arguments arenull
- Since:
- 2.0
-
buildView
Take any actions specific to this VDL implementation to cause the argument
UIViewRoot
which must have been created via a call tocreateView(jakarta.faces.context.FacesContext, java.lang.String)
, to be populated with children.The Facelets implementation must insure that markup comprising the view must be executed, with the
UIComponent
instances in the view being encountered in the same depth-first order as in other lifecycle methods defined onUIComponent
, and added to the view (but not rendered) during the traversal. The runtime must guarantee that the view must be fully populated before any of the following happen.-
The
PhaseListener.afterPhase(jakarta.faces.event.PhaseEvent)
method of anyPhaseListener
s attached to the application is called -
The
UIViewRoot
phase listener installed viaUIViewRoot.setAfterPhaseListener(jakarta.el.MethodExpression)
orUIViewRoot.addPhaseListener(jakarta.faces.event.PhaseListener)
are called.
If the
root
is already populated with children, the view must still be re-built, but care must be taken to ensure that the existing components are correctly paired up with their VDL counterparts in the VDL page. Also, any system events that would normally be generated during the adding or removing of components from the view must be temporarily disabled during the creation of the view and then re-enabled when the view has been built.- Parameters:
context
- theFacesContext
for this requestroot
- theUIViewRoot
to populate with children using techniques specific to this VDL implementation.- Throws:
IOException
- if view cannot be built for any reason
-
-
renderView
Render a view rooted at argument
view
. See section 7.7.2 "Default ViewDeclarationLanguage Implementation" of the Jakarta Faces Specification Document for the specification of the default implementation.- Parameters:
context
- theFacesContext
for this request.view
- theUIViewRoot
from an early call tocreateView(jakarta.faces.context.FacesContext, java.lang.String)
orrestoreView(jakarta.faces.context.FacesContext, java.lang.String)
.- Throws:
NullPointerException
- if any of the arguments arenull
IOException
- if the view cannot be rendered for any reason
-
getComponentMetadata
Return a reference to the component metadata for the composite component represented by the argument
componentResource
, ornull
if the metadata cannot be found. See section 7.7.2 "Default ViewDeclarationLanguage Implementation" of the Jakarta Faces Specification Document for the specification of the default implementation. Jakarta Server Pages implementations must throwUnsupportedOperationException
.- Parameters:
context
- TheFacesContext
for this request.componentResource
- TheResource
that represents the component.- Returns:
- the component metadata
- Throws:
NullPointerException
- if any of the arguments arenull
.FacesException
- if there is an error in obtaining the metadataUnsupportedOperationException
- if this is a Jakarta Server Pages VDL implementation.- Since:
- 2.0
-
getScriptComponentResource
public abstract Resource getScriptComponentResource(FacesContext context, Resource componentResource) Take implementation specific action to discover a
Resource
given the argumentcomponentResource
. See section 7.7.2 "Default ViewDeclarationLanguage Implementation" of the Jakarta Faces Specification Document for the specification of the default implementation. Jakarta Server Pages implementations must throwUnsupportedOperationException
.- Parameters:
context
- TheFacesContext
for this request.componentResource
- TheResource
that represents the component.- Returns:
- the
Resource
corresponding to the argumentcomponentResource
- Throws:
NullPointerException
- if any of the arguments arenull
.FacesException
- if there is an error in obtaining the script component resourceUnsupportedOperationException
- if this is a Jakarta Server Pages VDL implementation.- Since:
- 2.0
-
createComponent
public UIComponent createComponent(FacesContext context, String taglibURI, String tagName, Map<String, Object> attributes) Create a component given a
ViewDeclarationLanguage
specific tag library URI and tag name. The runtime must support this method operating for the Facelets VDL. Other kinds ofViewDeclarationLanguage
may be supported but are not required to be supported. For backward compatibility with decoratedViewDeclrationLanguage
implementations that do not override this method, a default implementation is provided that returnsnull
. However, any implementation that is compliant with the version of the specification in which this method was introduced must implement this method.- Parameters:
context
- theFacesContext
for this requesttaglibURI
- the fully qualified tag library URI that contains the componenttagName
- the name of the tag within that library that exposes the componentattributes
- any name=value pairs that would otherwise have been given on the markup that would cause the creation of this component ornull
if no attributes need be given.- Returns:
- the newly created component
- Throws:
NullPointerException
- ifcontext
,taglibURI
, ortagName
arenull
- Since:
- 2.2
-
retargetAttachedObjects
public void retargetAttachedObjects(FacesContext context, UIComponent topLevelComponent, List<AttachedObjectHandler> handlers) Assuming the component metadata for argument
topLevelComponent
has been made available by an earlier call togetComponentMetadata(jakarta.faces.context.FacesContext, jakarta.faces.application.Resource)
, leverage the component metadata for the purpose of re-targeting attached objects from the top level composite component to the individualAttachedObjectTarget
instances inside the composite component. This method must be called by theViewDeclarationLanguage
implementation when creating theUIComponent
tree when a composite component usage is encountered.An algorithm semantically equivalent to the following must be implemented.
-
Obtain the metadata for the composite component. Currently this entails getting the value of the
UIComponent.BEANINFO_KEY
component attribute, which will be an instance ofBeanInfo
. If the metadata cannot be found, log an error message and return. -
Get the
BeanDescriptor
from theBeanInfo
. -
Get the value of the
AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY
from theBeanDescriptor
'sgetValue()
method. This will be aList<
. Let this be targetList.AttachedObjectTarget
> -
For each curHandler entry in the argument
handlers
-
Let forAttributeValue be the return from
AttachedObjectHandler.getFor()
. -
For each curTarget entry in targetList, the first of the following items that causes a match will take this action:
For each
UIComponent
in the list returned from curTarget.getTargets(), call curHandler.applyAttachedObject(), passing theFacesContext
and theUIComponent
.and cause this inner loop to terminate.
-
If curHandler is an instance of
ActionSource2AttachedObjectHandler
and curTarget is an instance ofActionSource2AttachedObjectTarget
, and curTarget.getName() is equal to curTargetName, consider it a match. -
If curHandler is an instance of
EditableValueHolderAttachedObjectHandler
and curTarget is an instance ofEditableValueHolderAttachedObjectTarget
, and curTarget.getName() is equal to curTargetName, consider it a match. -
If curHandler is an instance of
ValueHolderAttachedObjectHandler
and curTarget is an instance ofValueHolderAttachedObjectTarget
, and curTarget.getName() is equal to curTargetName, consider it a match. -
If curHandler is an instance of
BehaviorHolderAttachedObjectHandler
and curTarget is an instance ofBehaviorHolderAttachedObjectTarget
, and either of the following conditions are true,- curHandler.getEventName() is not
null
and is equal to curTargetName. - curHandler.getEventName() is
null
and curTarget.isDefaultEvent() istrue
.
consider it a match.
- curHandler.getEventName() is not
-
-
The implementation must support retargeting attached objects from the top level compsite component to targets that are composite and non-composite components.
An implementation is provided that will throw
UnsupportedOperationException
. A Faces implementation compliant with version 2.0 and beyond of the specification must override this method.- Parameters:
context
- the FacesContext for this request.topLevelComponent
- The UIComponent in the view to which the attached objects must be attached. This UIComponent must have its component metadata already associated and available from via the JavaBeans API.handlers
- the tag handlers for the attached objects- Throws:
NullPointerException
- if any of the arguments arenull
.- Since:
- 2.0
-
-
retargetMethodExpressions
Assuming the component metadata for argument
topLevelComponent
has been made available by an earlier call togetComponentMetadata(jakarta.faces.context.FacesContext, jakarta.faces.application.Resource)
, leverage the component metadata for the purpose of re-targeting any method expressions from the top level component to the appropriate inner component. For each attribute that is aMethodExpression
(as indicated by the presence of a "method-signature
" attribute and the absence of a "type
" attribute), the following action must be taken:-
Get the value of the targets attribute. If the value is a
ValueExpression
evaluate it. If there is no targets attribute, let the name of the metadata element be the evaluated value of the targets attribute. -
Interpret targets as a space (not tab) separated list of ids. For each entry in the list:
-
Find the inner component of the topLevelComponent with the id equal to the current list entry. For discussion, this component is called target. If not found, log and error and continue to the next attribute.
-
For discussion the declared name of the attribute is called name.
-
In the attributes map of the topLevelComponent, look up the entry under the key name. Assume the result is a
ValueExpression
. For discussion, this is attributeValueExpression. If not found, log an error and continue to the next attribute. -
If name is equal to the string "action", or "actionListener" without the quotes, assume target is an
ActionSource2
. -
If name is equal to the string "validator", or "valueChangeListener" without the quotes, assume target is an
EditableValueHolder
. -
Call
getExpressionString()
on the attributeValueExpression and use that string to create aMethodExpression
of the appropriate signature for name. -
If name is not equal to any of the previously listed strings, call
getExpressionString()
on the attributeValueExpression and use that string to create aMethodExpression
where the signature is created based on the value of the "method-signature
" attribute of the<composite:attribute />
tag. -
Let the resultant
MethodExpression
be called attributeMethodExpression for discussion. -
If name is equal to the string "action" without the quotes, call
ActionSource2.setActionExpression(jakarta.el.MethodExpression)
on target, passing attributeMethodExpression. -
If name is equal to the string "actionListener" without the quotes, call
ActionSource.addActionListener(jakarta.faces.event.ActionListener)
on target, passing attributeMethodExpression wrapped in aMethodExpressionActionListener
. -
If name is equal to the string "validator" without the quotes, call
EditableValueHolder.addValidator(jakarta.faces.validator.Validator)
on target, passing attributeMethodExpression wrapped in aMethodExpressionValidator
. -
If name is equal to the string "valueChangeListener" without the quotes, call
EditableValueHolder.addValueChangeListener(jakarta.faces.event.ValueChangeListener)
on target, passing attributeMethodExpression wrapped in aMethodExpressionValueChangeListener
. -
Otherwise, assume that the
MethodExpression
should be placed in the components attribute set. The runtme must create theMethodExpression
instance based on the value of the "method-signature
" attribute.
-
An implementation is provided that will throw
UnsupportedOperationException
. A Faces implementation compliant with version 2.0 and beyond of the specification must override this method.- Parameters:
context
- the FacesContext for this request.topLevelComponent
- The UIComponent in the view to which the attached objects must be attached. This UIComponent must have its component metadata already associated and available from via the JavaBeans API.- Throws:
NullPointerException
- ifcontext
ortopLevelComponent
isnull
.- Since:
- 2.0
-
-
calculateResourceLibraryContracts
Return the list of resource library contracts that will be made available for use in the view specified by the argument
viewId
. If no match is found, return an empty list. See section 7.7.2 "Default ViewDeclarationLanguage Implementation" of the Jakarta Faces Specification Document for the specification of the default implementation. For backward compatibility with prior implementations, an implementation is provided that returnsnull
, but any implementation compliant with the version of the specification in which this method was introduced must implement it as specified in section 7.7.2 "Default ViewDeclarationLanguage Implementation" of the Jakarta Faces Specification Document.- Parameters:
context
- theFacesContext
for this requestviewId
- the view id for which the applicable resource library contracts should be calculated.- Returns:
- the calculated list of resource library contract names
- Since:
- 2.2
-
getStateManagementStrategy
public abstract StateManagementStrategy getStateManagementStrategy(FacesContext context, String viewId) For implementations that want to control the implementation of state saving and restoring, the
StateManagementStrategy
allows them to do so. Returningnull
indicates that the implementation wishes the runtime to handle the state saving and restoring. Implementations that provide the VDL for Facelets for Jakarta Faces 2.0 and later must return non-null
from this method.- Parameters:
context
- theFacesContext
for the current request.viewId
- the view id.- Returns:
- the strategy as specified above
- Since:
- 2.0
-
viewExists
Tests whether a physical resource corresponding to the specified viewId exists.
The default implementation uses
ResourceHandler.createViewResource(jakarta.faces.context.FacesContext, java.lang.String)
to locate the physical resource.- Parameters:
context
- TheFacesContext
for this request.viewId
- the view id to test- Returns:
- the result as specified above
- Since:
- 2.1
-
getViews
Return a
Stream
possibly lazily populated by walking the view tree rooted at a given initial path. The view tree is traversed breadth-first, the elements in the stream are logical view ids.This method works as if invoking it were equivalent to evaluating the expression:
getViewResources(facesContext, start, Integer.MAX_VALUE, options)
- Parameters:
facesContext
- TheFacesContext
for this request.path
- The initial path from which to start looking for viewsoptions
- The options to influence the traversal. SeeViewVisitOption
for details on those.- Returns:
- the
Stream
of view ids - Since:
- 2.3
-
getViews
public Stream<String> getViews(FacesContext facesContext, String path, int maxDepth, ViewVisitOption... options) Return a
Stream
possibly lazily populated by walking the view tree rooted at a given initial path. The view tree is traversed breadth-first, the elements in the stream are logical view ids.The
maxDepth
parameter is the maximum depth of directory levels to visit beyond the initial path, which is always visited. The value is relative to the root (/
), not to the given initial path. E.g. givenmaxDepth
=3
and initial path/foo/
, visiting will proceed up to/foo/bar/
, where/
counts as depth1
,/foo/
as depth2
and/foo/bar/
as depth3
. A value lower or equal to the depth of the initial path means that only the initial path is visited. A value ofMAX_VALUE
may be used to indicate that all levels should be visited.- Parameters:
facesContext
- TheFacesContext
for this request.path
- The initial path from which to start looking for viewsmaxDepth
- The absolute maximum depth of nested directories to visit counted from the root (/
).options
- The options to influence the traversal. SeeViewVisitOption
for details on those.- Returns:
- the
Stream
of view ids - Since:
- 2.3
-
getId
Returns a non-null String that can be used to identify this view declaration language.
The default implementation returns the fully qualified class name of the view declaration language implementation. Subclasses may override to provide a more meaningful id.
- Returns:
- the id of this view declaration language
- Since:
- 2.1
-