org.apache.click.util
Class PageImports

java.lang.Object
  extended by org.apache.click.util.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:

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: Please also see Page.getHeadElements(), Control.getHeadElements().


Field Summary
protected  List<CssImport> cssImports
          The list of CSS import lines.
protected  List<CssStyle> cssStyles
          The list of CSS styles.
protected  List<Element> headElements
          The list of head elements.
protected  boolean initialized
          The page imports initialized flag.
protected  List<JsImport> jsImports
          The list of JS import lines.
protected  List<JsScript> jsScripts
          The list of JS script block lines.
protected  Page page
          The page instance.
 
Constructor Summary
PageImports(Page page)
          Create a page control HTML includes object.
 
Method Summary
 void add(Element element)
          Add the given Element to the Page HEAD elements.
 void addAll(List<Element> elements)
          Add the given list of Elements to the Page HEAD elements.
 List<Element> getHeadElements()
          Return the list of processed HEAD elements, excluding any JavaScript elements.
 List<Element> getJsElements()
          Return the list of processed JavaScript elements.
 boolean isInitialized()
          Return true if the page imports have been initialized.
 void populateRequest(HttpServletRequest request, Map<String,Object> model)
          Populate the specified request with html import keys.
 void populateTemplateModel(Map<String,Object> model)
          Populate the specified model with html import keys.
 void processControl(Control control)
          Process the given control HEAD elements.
 void processControls(List<Control> controls)
          Process the HEAD elements of the given list of Controls.
protected  void processHeadElements(List<Element> elements)
          Process the given list of HEAD elements.
protected  void processPageControls()
          Process the Page's set of control HEAD elements.
protected  void renderAllIncludes(HtmlStringBuffer buffer)
          Deprecated. rather use renderHeadElements(org.apache.click.util.HtmlStringBuffer) and renderJsElements(org.apache.click.util.HtmlStringBuffer)
protected  void renderCssElements(HtmlStringBuffer buffer)
          Render an HTML representation of all all the page's HTML CSS imports and styles.
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.
protected  void renderJsElements(HtmlStringBuffer buffer)
          Render an HTML representation of all the page's HTML JavaScript imports and scripts.
 void setInitialized(boolean initialized)
          Set whether the page imports have been initialized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 Page page
The page instance.

Constructor Detail

PageImports

public PageImports(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(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<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(org.apache.click.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(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(java.util.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

renderAllIncludes

protected void renderAllIncludes(HtmlStringBuffer buffer)
Deprecated. rather use renderHeadElements(org.apache.click.util.HtmlStringBuffer) and renderJsElements(org.apache.click.util.HtmlStringBuffer)

Render an HTML representation of all the page's HTML imports, including: CSS imports, CSS styles, JS imports and JS scripts.

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(org.apache.click.element.Element) for every Element entry in the specified list.

Parameters:
elements - the list of HEAD elements to process