Class PageImports


  • public class PageImports
    extends Object
    Provides a utility object for rendering a Page's HEAD elements and control HEAD elements.

    PageImports automatically makes the HEAD elements available to Velocity templates and JSP pages through the following variables:

    • $headElements - this variable includes all HEAD elements except JavaScript elements
    • $jsElements - this variable includes only JavaScript elements
    By splitting JavaScript elements from other HEAD elements allows you to place JavaScript elements at the bottom of the Page which allows the HTML content to be rendered faster.

    To use the HEAD elements simply reference them in your page template. For example:

     <html>
      <head>
       $headElements
      </head>
      <body>
       $form
    
      $jsElements
      <body>
     </html> 
    Its not always possible to move the JavaScript elements to the bottom of the Page, for example there might be JavaScript scoping issues. In those situations you can simply place the JavaScript elements variable in the Page HEAD section:
     <html>
      <head>
       $headElements
       $jsElements
      </head>
      <body>
       $form
      <body>
     </html> 
    Please note: the variables $headElements and $jsElements are new in Click 2.1.0. For backwards compatibility the HEAD elements are also available through the following variables:
    • $imports - this variable includes all HEAD elements including JavaScript and Css elements
    • $cssImports - this variable includes only Css elements
    • $jsImports - this variable includes only Javascript elements
    Please also see Page.getHeadElements(), Control.getHeadElements().
    • Field Detail

      • initialized

        protected boolean initialized
        The page imports initialized flag.
      • headElements

        protected List<Element> headElements
        The list of head elements.
      • cssImports

        protected List<CssImport> cssImports
        The list of CSS import lines.
      • jsImports

        protected List<JsImport> jsImports
        The list of JS import lines.
      • jsScripts

        protected List<JsScript> jsScripts
        The list of JS script block lines.
      • cssStyles

        protected List<CssStyle> cssStyles
        The list of CSS styles.
      • page

        protected final org.openidentityplatform.openam.click.Page page
        The page instance.
    • Constructor Detail

      • PageImports

        public PageImports​(org.openidentityplatform.openam.click.Page page)
        Create a page control HTML includes object.
        Parameters:
        page - the page to provide HTML includes for
    • Method Detail

      • add

        public void add​(Element element)
        Add the given Element to the Page HEAD elements.
        Parameters:
        element - the Element to add
        Throws:
        IllegalArgumentException - if the Element is null
      • addAll

        public void addAll​(List<Element> elements)
        Add the given list of Elements to the Page HEAD elements.
        Parameters:
        elements - the list of Elements to add to the Page HEAD elements
        Throws:
        IllegalArgumentException - is the list of Elements are null
      • isInitialized

        public boolean isInitialized()
        Return true if the page imports have been initialized.
        Returns:
        true if the page imports have been initialized
      • setInitialized

        public void setInitialized​(boolean initialized)
        Set whether the page imports have been initialized.
        Parameters:
        initialized - the page imports have been initialized flag
      • populateTemplateModel

        public void populateTemplateModel​(Map<String,​Object> model)
        Populate the specified model with html import keys.
        Parameters:
        model - the model to populate with html import keys
      • populateRequest

        public void populateRequest​(jakarta.servlet.http.HttpServletRequest request,
                                    Map<String,​Object> model)
        Populate the specified request with html import keys.
        Parameters:
        request - the http request to populate
        model - the model to populate with html import keys
      • processControls

        public void processControls​(List<org.openidentityplatform.openam.click.Control> controls)
        Process the HEAD elements of the given list of Controls. You can retrieve the processed HEAD elements through getHeadElements() and getJsElements().

        This method delegates to processControl(Control) to add the given Control's HEAD elements to the Page imports.

        Parameters:
        controls - the list of Controls which HEAD elements to process
      • processControl

        public void processControl​(org.openidentityplatform.openam.click.Control control)
        Process the given control HEAD elements. This method will recursively process Containers and all child controls. You can retrieve the processed HEAD elements through getHeadElements() and getJsElements().

        This method delegates to processHeadElements(List) to add the HEAD elements to the Page imports.

        Parameters:
        control - the control to process
      • getHeadElements

        public final List<Element> getHeadElements()
        Return the list of processed HEAD elements, excluding any JavaScript elements. To retrieve JavaScript elements please see getJsElements().
        Returns:
        the list of processed HEAD elements
      • getJsElements

        public final List<Element> getJsElements()
        Return the list of processed JavaScript elements.
        Returns:
        the list of processed JavaScript elements
      • renderHeadElements

        protected void renderHeadElements​(HtmlStringBuffer buffer)
        Render an HTML representation of all the page's HTML head elements, including: CSS imports, CSS styles, Title and Meta elements.
        Parameters:
        buffer - the specified buffer to render the page's HTML imports to
      • renderCssElements

        protected void renderCssElements​(HtmlStringBuffer buffer)
        Render an HTML representation of all all the page's HTML CSS imports and styles.
        Parameters:
        buffer - the specified buffer to render the page's HTML imports to
      • renderJsElements

        protected void renderJsElements​(HtmlStringBuffer buffer)
        Render an HTML representation of all the page's HTML JavaScript imports and scripts.
        Parameters:
        buffer - the specified buffer to render the page's HTML imports to
      • processPageControls

        protected void processPageControls()
        Process the Page's set of control HEAD elements.
      • processHeadElements

        protected void processHeadElements​(List<Element> elements)
        Process the given list of HEAD elements.

        This method invokes add(Element) for every Element entry in the specified list.

        Parameters:
        elements - the list of HEAD elements to process