Class FaceletViewHandlingStrategy

    • Field Detail

      • IS_BUILDING_METADATA

        public static final String IS_BUILDING_METADATA
      • RESOURCE_LIBRARY_CONTRACT_DATA_STRUCTURE_KEY

        public static final String RESOURCE_LIBRARY_CONTRACT_DATA_STRUCTURE_KEY
    • Constructor Detail

      • FaceletViewHandlingStrategy

        public FaceletViewHandlingStrategy()
    • Method Detail

      • isBuildingMetadata

        public static boolean isBuildingMetadata​(FacesContext context)
      • getViewMetadata

        public ViewMetadata getViewMetadata​(FacesContext context,
                                            String viewId)
        Description copied from class: 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 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.

        Specified by:
        getViewMetadata in class ViewDeclarationLanguage
        Parameters:
        context - The FacesContext for this request.
        viewId - the view id from which to extract the metadata
        Returns:
        the view metadata
      • getStateManagementStrategy

        public StateManagementStrategy getStateManagementStrategy​(FacesContext context,
                                                                  String viewId)
        Description copied from class: 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 Faces 2.0 and later must return non-null from this method.

        Specified by:
        getStateManagementStrategy in class ViewDeclarationLanguage
        Parameters:
        context - the FacesContext for the current request.
        viewId - the view id.
        Returns:
        the strategy as specified above
      • getComponentMetadata

        public BeanInfo getComponentMetadata​(FacesContext context,
                                             Resource ccResource)
        Called by Application._createComponent(Resource). This method creates two temporary UIComponent instances to aid in the creation of the compcomp metadata. These instances no longer needed after the method returns and can be safely garbage collected. PENDING(): memory analysis should be done to verify there are no memory leaks as a result of this implementation. The instances are 1. tmp: a jakarta.faces.NamingContainer to serve as the temporary top level component 2. facetComponent: a jakarta.faces.Panel to serve as the parent UIComponent that is passed to Facelets so that the <cc:interface> section can be parsed and understood. Per the compcomp spec, tmp has the compcomp Resource stored in its attr set under the key Resource.COMPONENT_RESOURCE_KEY. tmp has the facetComponent added as its UIComponent.COMPOSITE_FACET_NAME facet.
        Specified by:
        getComponentMetadata in class ViewDeclarationLanguage
        Parameters:
        context - The FacesContext for this request.
        ccResource - The Resource that represents the component.
        Returns:
        the component metadata
      • retargetMethodExpressions

        public void retargetMethodExpressions​(FacesContext context,
                                              UIComponent topLevelComponent)
        Description copied from class: 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.

        Overrides:
        retargetMethodExpressions in class ViewDeclarationLanguage
        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.
      • createComponent

        public UIComponent createComponent​(FacesContext context,
                                           String taglibURI,
                                           String tagName,
                                           Map<String,​Object> attributes)
        Description copied from class: 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.

        Overrides:
        createComponent in class ViewDeclarationLanguage
        Parameters:
        context - the FacesContext for this request
        taglibURI - the fully qualified tag library URI that contains the component
        tagName - the name of the tag within that library that exposes the component
        attributes - 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.
        Returns:
        the newly created component
      • calculateResourceLibraryContracts

        public List<String> calculateResourceLibraryContracts​(FacesContext context,
                                                              String viewId)
        Description copied from class: 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 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 returns null, 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.

        Overrides:
        calculateResourceLibraryContracts in class ViewDeclarationLanguage
        Parameters:
        context - the FacesContext for this request
        viewId - the view id for which the applicable resource library contracts should be calculated.
        Returns:
        the calculated list of resource library contract names
      • getViews

        public Stream<String> getViews​(FacesContext context,
                                       String path,
                                       ViewVisitOption... options)
        Description copied from class: 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:

         getViewResources(facesContext, start, Integer.MAX_VALUE, options)
         
        Put differently, it visits all levels of the resource tree.
        Overrides:
        getViews in class ViewDeclarationLanguage
        Parameters:
        context - The FacesContext for this request.
        path - The initial path from which to start looking for views
        options - The options to influence the traversal. See ViewVisitOption for details on those.
        Returns:
        the Stream of view ids
      • getViews

        public Stream<String> getViews​(FacesContext context,
                                       String path,
                                       int maxDepth,
                                       ViewVisitOption... options)
        Description copied from class: 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.

        Overrides:
        getViews in class ViewDeclarationLanguage
        Parameters:
        context - The FacesContext for this request.
        path - The initial path from which to start looking for views
        maxDepth - 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.
        Returns:
        the Stream of view ids
      • getId

        public String getId()
        Description copied from class: ViewDeclarationLanguage

        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.

        Overrides:
        getId in class ViewDeclarationLanguage
        Returns:
        the id of this view declaration language
      • initialize

        protected void initialize()
        Initialize the core Facelets runtime.
      • initializeMappings

        protected void initializeMappings()
        Initialize mappings, during the first request.
      • handleRenderException

        protected void handleRenderException​(FacesContext context,
                                             Exception e)
                                      throws IOException
        Handles the case where rendering throws an Exception.
        Parameters:
        context - the FacesContext for the current request
        e - the caught Exception
        Throws:
        IOException - if the custom debug content cannot be written
      • handleFaceletNotFound

        protected void handleFaceletNotFound​(FacesContext context,
                                             String viewId,
                                             String message)
                                      throws IOException
        Handles the case where a Facelet cannot be found.
        Parameters:
        context - the FacesContext for the current request
        viewId - the view ID that was to be mapped to a Facelet
        message - optional message to include in the 404
        Throws:
        IOException - if an error occurs sending the 404 to the client
      • getResponseEncoding

        protected String getResponseEncoding​(FacesContext context,
                                             String orig)
        Parameters:
        context - the FacesContext for the current request
        orig - the original encoding
        Returns:
        the encoding to be used for this response
      • getResponseContentType

        protected String getResponseContentType​(FacesContext context,
                                                String orig)
        Parameters:
        context - the FacesContext for the current request
        orig - the original contentType
        Returns:
        the content type to be used for this response