public class FaceletViewHandlingStrategy extends ViewHandlingStrategy
ViewHandlingStrategy handles Facelets/PDL-based views.| Modifier and Type | Class and Description |
|---|---|
protected static class |
FaceletViewHandlingStrategy.NullWriter
Simple no-op writer.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
IS_BUILDING_METADATA |
static String |
RESOURCE_LIBRARY_CONTRACT_DATA_STRUCTURE_KEY |
associate, webConfig| Constructor and Description |
|---|
FaceletViewHandlingStrategy() |
| Modifier and Type | Method and Description |
|---|---|
void |
buildView(jakarta.faces.context.FacesContext ctx,
jakarta.faces.component.UIViewRoot view)
Take any actions specific to this VDL implementation to cause the argument
|
List<String> |
calculateResourceLibraryContracts(jakarta.faces.context.FacesContext context,
String viewId)
Return the list of resource library contracts that will be made available for use in the view specified by the
argument |
jakarta.faces.component.UIComponent |
createComponent(jakarta.faces.context.FacesContext context,
String taglibURI,
String tagName,
Map<String,Object> attributes)
Create a component given a |
BeanInfo |
createComponentMetadata(jakarta.faces.context.FacesContext context,
jakarta.faces.application.Resource ccResource) |
protected jakarta.faces.context.ResponseWriter |
createResponseWriter(jakarta.faces.context.FacesContext context) |
jakarta.faces.component.UIViewRoot |
createView(jakarta.faces.context.FacesContext ctx,
String viewId)
Create a |
BeanInfo |
getComponentMetadata(jakarta.faces.context.FacesContext context,
jakarta.faces.application.Resource ccResource)
Called by Application._createComponent(Resource).
|
String |
getId()
Returns a non-null String that can be used to identify this view declaration language. |
protected String |
getResponseContentType(jakarta.faces.context.FacesContext context,
String orig) |
protected String |
getResponseEncoding(jakarta.faces.context.FacesContext context,
String orig) |
jakarta.faces.application.Resource |
getScriptComponentResource(jakarta.faces.context.FacesContext context,
jakarta.faces.application.Resource componentResource)
Take implementation specific action to discover a |
jakarta.faces.view.StateManagementStrategy |
getStateManagementStrategy(jakarta.faces.context.FacesContext context,
String viewId)
For implementations that want to control the implementation of state saving and restoring, the
|
jakarta.faces.view.ViewMetadata |
getViewMetadata(jakarta.faces.context.FacesContext context,
String viewId)
Return a reference to the view metadata for the view represented by the argument |
Stream<String> |
getViews(jakarta.faces.context.FacesContext context,
String path,
int maxDepth,
jakarta.faces.application.ViewVisitOption... options)
Return a |
Stream<String> |
getViews(jakarta.faces.context.FacesContext context,
String path,
jakarta.faces.application.ViewVisitOption... options)
Return a |
protected void |
handleFaceletNotFound(jakarta.faces.context.FacesContext context,
String viewId,
String message)
Handles the case where a Facelet cannot be found.
|
protected void |
handleRenderException(jakarta.faces.context.FacesContext context,
Exception e)
Handles the case where rendering throws an Exception.
|
boolean |
handlesViewId(String viewId) |
protected void |
initialize()
Initialize the core Facelets runtime.
|
protected void |
initializeMappings()
Initialize mappings, during the first request.
|
static boolean |
isBuildingMetadata(jakarta.faces.context.FacesContext context) |
void |
renderView(jakarta.faces.context.FacesContext ctx,
jakarta.faces.component.UIViewRoot viewToRender)
Render a view rooted at argument |
jakarta.faces.component.UIViewRoot |
restoreView(jakarta.faces.context.FacesContext context,
String viewId)
If
UIDebug.debugRequest(jakarta.faces.context.FacesContext)} is true, simply return a new
UIViewRoot(), otherwise, call the default logic. |
void |
retargetAttachedObjects(jakarta.faces.context.FacesContext context,
jakarta.faces.component.UIComponent topLevelComponent,
List<jakarta.faces.view.AttachedObjectHandler> handlers)
Assuming the component metadata for argument
|
void |
retargetMethodExpressions(jakarta.faces.context.FacesContext context,
jakarta.faces.component.UIComponent topLevelComponent)
Assuming the component metadata for argument |
boolean |
viewExists(jakarta.faces.context.FacesContext context,
String viewId)
Tests whether a physical resource corresponding to the specified viewId exists. |
public static final String IS_BUILDING_METADATA
public static final String RESOURCE_LIBRARY_CONTRACT_DATA_STRUCTURE_KEY
public static boolean isBuildingMetadata(jakarta.faces.context.FacesContext context)
public jakarta.faces.component.UIViewRoot restoreView(jakarta.faces.context.FacesContext context,
String viewId)
If UIDebug.debugRequest(jakarta.faces.context.FacesContext)} is true, simply return a new
UIViewRoot(), otherwise, call the default logic.
restoreView in class ViewHandlingStrategycontext - the FacesContext for this request.viewId - the identifier for a previously rendered view.ViewDeclarationLanguage.restoreView(jakarta.faces.context.FacesContext, java.lang.String)public jakarta.faces.view.ViewMetadata getViewMetadata(jakarta.faces.context.FacesContext context,
String viewId)
jakarta.faces.view.ViewDeclarationLanguage
Return a reference to the view metadata for the view represented by the argument viewId, or
null if the metadata cannot be found. See section JSF.7.7.2 for the specification of the default
implementation. Facelets for Jakarta Server Faces 2 implementation must return non-null. Jakarta Server
Pages implementations must return null.
getViewMetadata in class jakarta.faces.view.ViewDeclarationLanguagecontext - The FacesContext for this request.viewId - the view id from which to extract the metadatapublic jakarta.faces.component.UIViewRoot createView(jakarta.faces.context.FacesContext ctx,
String viewId)
jakarta.faces.view.ViewDeclarationLanguage
Create a UIViewRoot from the VDL contained in the artifact
referenced by the argument viewId. See section JSF.7.7.2 for the
specification of the default implementation.
createView in class ViewHandlingStrategyctx - the FacesContext for this request.viewId - the identifier of an artifact that contains the VDL syntax that describes this view.ViewDeclarationLanguage.createView(jakarta.faces.context.FacesContext, java.lang.String)public void buildView(jakarta.faces.context.FacesContext ctx,
jakarta.faces.component.UIViewRoot view)
throws IOException
jakarta.faces.view.ViewDeclarationLanguage
Take any actions specific to this VDL implementation to cause the argument
UIViewRoot which must have been created via a call to ViewDeclarationLanguage.createView(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 on UIComponent, 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 any PhaseListeners attached to the
application is called
The UIViewRoot phase listener installed via
UIViewRoot.setAfterPhaseListener(jakarta.el.MethodExpression) or
UIViewRoot.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.
buildView in class jakarta.faces.view.ViewDeclarationLanguagectx - the FacesContext for this requestview - the UIViewRoot to populate with children using techniques specific to this VDL
implementation.IOException - if view cannot be built for any reasonViewDeclarationLanguage.buildView(FacesContext, UIViewRoot)public void renderView(jakarta.faces.context.FacesContext ctx,
jakarta.faces.component.UIViewRoot viewToRender)
throws IOException
jakarta.faces.view.ViewDeclarationLanguage
Render a view rooted at argumentview. See section JSF.7.7.2 for the specification of the default
implementation.
renderView in class jakarta.faces.view.ViewDeclarationLanguagectx - the FacesContext for this request.viewToRender - the UIViewRoot from an early call to ViewDeclarationLanguage.createView(jakarta.faces.context.FacesContext, java.lang.String) or ViewDeclarationLanguage.restoreView(jakarta.faces.context.FacesContext, java.lang.String).IOException - if the view cannot be rendered for any reasonViewDeclarationLanguage.renderView(jakarta.faces.context.FacesContext,
jakarta.faces.component.UIViewRoot)public jakarta.faces.view.StateManagementStrategy getStateManagementStrategy(jakarta.faces.context.FacesContext context,
String viewId)
jakarta.faces.view.ViewDeclarationLanguage
For implementations that want to control the implementation of state saving and restoring, the
StateManagementStrategy allows them to do so. Returning null indicates that the implementation
wishes the runtime to handle the state saving and restoring. Implementations that provide the VDL for Facelets for
Jakarta Server Faces 2.0 and later must return non-null from this method.
getStateManagementStrategy in class jakarta.faces.view.ViewDeclarationLanguagecontext - the FacesContext for the current request.viewId - the view id.public BeanInfo getComponentMetadata(jakarta.faces.context.FacesContext context, jakarta.faces.application.Resource ccResource)
getComponentMetadata in class jakarta.faces.view.ViewDeclarationLanguagecontext - The FacesContext for this request.ccResource - The Resource that represents the component.public BeanInfo createComponentMetadata(jakarta.faces.context.FacesContext context, jakarta.faces.application.Resource ccResource)
public jakarta.faces.application.Resource getScriptComponentResource(jakarta.faces.context.FacesContext context,
jakarta.faces.application.Resource componentResource)
jakarta.faces.view.ViewDeclarationLanguage
Take implementation specific action to discover a Resource given the argument
componentResource. See section JSF.7.7.2 for the specification of the default implementation. Jakarta
Server Pages implementations must throw UnsupportedOperationException.
getScriptComponentResource in class jakarta.faces.view.ViewDeclarationLanguagecontext - The FacesContext for this request.componentResource - The Resource that represents the component.Resource corresponding to the argument componentResourceViewDeclarationLanguage.getScriptComponentResource(jakarta.faces.context.FacesContext,
jakarta.faces.application.Resource)public void retargetAttachedObjects(jakarta.faces.context.FacesContext context,
jakarta.faces.component.UIComponent topLevelComponent,
List<jakarta.faces.view.AttachedObjectHandler> handlers)
jakarta.faces.view.ViewDeclarationLanguage
Assuming the component metadata for argument
topLevelComponent has been made available by an earlier call to
ViewDeclarationLanguage.getComponentMetadata(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 individual AttachedObjectTarget instances
inside the composite component. This method must be called by the ViewDeclarationLanguage implementation when
creating the UIComponent 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 of BeanInfo. If the
metadata cannot be found, log an error message and return.
Get the BeanDescriptor from the BeanInfo.
Get the value of the AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY from the BeanDescriptor's
getValue() method. This will be a List<. 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 the
FacesContext and the UIComponent.
and cause this inner loop to terminate.
If curHandler is an instance of ActionSource2AttachedObjectHandler and curTarget is an
instance of ActionSource2AttachedObjectTarget, and curTarget.getName() is equal to
curTargetName, consider it a match.
If curHandler is an instance of EditableValueHolderAttachedObjectHandler and curTarget is
an instance of EditableValueHolderAttachedObjectTarget, and
curTarget.getName() is equal to curTargetName, consider it a match.
If curHandler is an instance of ValueHolderAttachedObjectHandler and curTarget is an
instance of ValueHolderAttachedObjectTarget, and curTarget.getName() is equal to
curTargetName, consider it a match.
If curHandler is an instance of BehaviorHolderAttachedObjectHandler and curTarget is an
instance of BehaviorHolderAttachedObjectTarget, and either of the following conditions are true,
null and is equal to curTargetName.null and curTarget.isDefaultEvent() is
true.consider it a match.
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.
retargetAttachedObjects in class jakarta.faces.view.ViewDeclarationLanguagecontext - 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 objectsViewDeclarationLanguage.retargetAttachedObjects(jakarta.faces.context.FacesContext,
jakarta.faces.component.UIComponent, java.util.List)public void retargetMethodExpressions(jakarta.faces.context.FacesContext context,
jakarta.faces.component.UIComponent topLevelComponent)
jakarta.faces.view.ViewDeclarationLanguage
Assuming the component metadata for argument topLevelComponent has been made available by an earlier
call to ViewDeclarationLanguage.getComponentMetadata(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 a MethodExpression (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 a
MethodExpression 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 a MethodExpression 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 a MethodExpressionActionListener.
If name is equal to the string "validator" without the quotes, call
EditableValueHolder.addValidator(jakarta.faces.validator.Validator) on target, passing
attributeMethodExpression wrapped in a MethodExpressionValidator.
If name is equal to the string "valueChangeListener" without the quotes, call
EditableValueHolder.addValueChangeListener(jakarta.faces.event.ValueChangeListener) on target, passing
attributeMethodExpression wrapped in a MethodExpressionValueChangeListener.
Otherwise, assume that the MethodExpression should be placed in the components attribute set. The runtme
must create the MethodExpression 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.
retargetMethodExpressions in class jakarta.faces.view.ViewDeclarationLanguagecontext - 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.ViewDeclarationLanguage.retargetMethodExpressions(jakarta.faces.context.FacesContext,
jakarta.faces.component.UIComponent)public jakarta.faces.component.UIComponent createComponent(jakarta.faces.context.FacesContext context,
String taglibURI,
String tagName,
Map<String,Object> attributes)
jakarta.faces.view.ViewDeclarationLanguage
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 of ViewDeclarationLanguage may be supported
but are not required to be supported. For backward compatibility with decorated ViewDeclrationLanguage
implementations that do not override this method, a default implementation is provided that returns null.
However, any implementation that is compliant with the version of the specification in which this method was
introduced must implement this method.
createComponent in class jakarta.faces.view.ViewDeclarationLanguagecontext - the FacesContext 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 or null if no attributes need be given.public List<String> calculateResourceLibraryContracts(jakarta.faces.context.FacesContext context, String viewId)
jakarta.faces.view.ViewDeclarationLanguage
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 JSF.7.7.2 for the specification of
the default implementation. For backward compatibility with prior implementations, an implementation is provided that
returns null, but any implementation compliant with the version of the specification in which this method was
introduced must implement it as specified in JSF.7.7.2.
calculateResourceLibraryContracts in class jakarta.faces.view.ViewDeclarationLanguagecontext - the FacesContext for this requestviewId - the view id for which the applicable resource library contracts should be calculated.public boolean viewExists(jakarta.faces.context.FacesContext context,
String viewId)
jakarta.faces.view.ViewDeclarationLanguageTests 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.
viewExists in class jakarta.faces.view.ViewDeclarationLanguagecontext - The FacesContext for this request.viewId - the view id to testpublic Stream<String> getViews(jakarta.faces.context.FacesContext context, String path, jakarta.faces.application.ViewVisitOption... options)
jakarta.faces.view.ViewDeclarationLanguage
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:
Put differently, it visits all levels of the resource tree.getViewResources(facesContext, start, Integer.MAX_VALUE, options)
getViews in class jakarta.faces.view.ViewDeclarationLanguagecontext - The FacesContext for this request.path - The initial path from which to start looking for viewsoptions - The options to influence the traversal. See ViewVisitOption for details on those.Stream of view idsjakarta.faces.view.ViewDeclarationLanguage#getViews(FacesContext, String)public Stream<String> getViews(jakarta.faces.context.FacesContext context, String path, int maxDepth, jakarta.faces.application.ViewVisitOption... options)
jakarta.faces.view.ViewDeclarationLanguage
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. given
maxDepth = 3 and initial path /foo/, visiting will proceed up to /foo/bar/, where
/ counts as depth 1, /foo/ as depth 2 and /foo/bar/ as depth 3. A
value lower or equal to the depth of the initial path means that only the initial path is visited. A value of
MAX_VALUE may be used to indicate that all levels should be visited.
getViews in class jakarta.faces.view.ViewDeclarationLanguagecontext - The FacesContext 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. See ViewVisitOption for details on those.Stream of view idsjakarta.faces.view.ViewDeclarationLanguage#getViews(FacesContext, String, int)public boolean handlesViewId(String viewId)
handlesViewId in class ViewHandlingStrategyviewId - the view ID to checktrue if assuming a default configuration and the view ID's extension is .xhtml
Otherwise try to match the view ID based on the configured extendsion and prefixes.WebConfiguration.WebContextInitParameter.FaceletsViewMappingspublic String getId()
jakarta.faces.view.ViewDeclarationLanguageReturns 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.
getId in class jakarta.faces.view.ViewDeclarationLanguageprotected void initialize()
protected void initializeMappings()
protected jakarta.faces.context.ResponseWriter createResponseWriter(jakarta.faces.context.FacesContext context)
throws IOException
context - the FacesContext for the current requestResponseWriter for processing the requestIOException - if the writer cannot be createdprotected void handleRenderException(jakarta.faces.context.FacesContext context,
Exception e)
throws IOException
context - the FacesContext for the current requeste - the caught ExceptionIOException - if the custom debug content cannot be writtenprotected void handleFaceletNotFound(jakarta.faces.context.FacesContext context,
String viewId,
String message)
throws IOException
context - the FacesContext for the current requestviewId - the view ID that was to be mapped to a Faceletmessage - optional message to include in the 404IOException - if an error occurs sending the 404 to the clientprotected String getResponseEncoding(jakarta.faces.context.FacesContext context, String orig)
context - the FacesContext for the current requestorig - the original encodingCopyright © 2010–2022 JBoss by Red Hat. All rights reserved.