com.ibm.xsp.component
Class UIScriptCollector

java.lang.Object
  extended by javax.faces.component.UIComponent
      extended by javax.faces.component.UIComponentBase
          extended by com.ibm.xsp.component.UIScriptCollector
All Implemented Interfaces:
com.ibm.xsp.ajax.AjaxPartialRefresh, javax.faces.component.StateHolder

public class UIScriptCollector
extends javax.faces.component.UIComponentBase
implements com.ibm.xsp.ajax.AjaxPartialRefresh

UIScriptCollector is a UIComponent that wraps other components on a JSF page. It is automatically inserted into the XPage by the root control. In Internet Explorer if you partial refresh an area where script tag appears before an input control, then the script is not inserted into the page during the refresh. The Script Collector control is used to avoid that issue by aggregating all JavaScript snippets that are output by different controls into one large script tag at the bottom of the page. During a partial refresh, the script tag will only contain scripts from controls that were in the updated area. Not intended to be subclassed.


Nested Class Summary
 
Nested classes/interfaces inherited from class javax.faces.component.UIComponentBase
javax.faces.component.UIComponentBase.AggregatedIterator, javax.faces.component.UIComponentBase.UnmodifiableIterator
 
Nested classes/interfaces inherited from class javax.faces.component.UIComponent
javax.faces.component.UIComponent.StateMap, javax.faces.component.UIComponent.StateMapEntry
 
Field Summary
static java.lang.String COMPONENT_FAMILY
          The standard component family for this component.
static java.lang.String COMPONENT_TYPE
          The standard component type for this component.
static java.lang.String RENDERER_TYPE
           
 
Fields inherited from class javax.faces.component.UIComponentBase
EMPTY_ITERATOR
 
Fields inherited from class javax.faces.component.UIComponent
_xspStateId
 
Constructor Summary
UIScriptCollector()
          Constructor.
 
Method Summary
 void addScript(java.lang.String newScript)
          Adds a new script for the bottom of the script block.
 void addScript(java.lang.String newScript, boolean force)
           
 void addScriptOnce(java.lang.String newScript)
          Adds a new script for the bottom of the script block, making sure the exact same script wasn't already added.
 void addScriptOnce(java.lang.String newScript, boolean force)
           
 void addScriptOnLoad(java.lang.String newScript)
          Adds a new script that should be executed on load
 void addScriptOnLoad(java.lang.String newScript, boolean force)
           
static UIScriptCollector find()
          Find the UIScriptCollector associated with the current page.
static UIScriptCollector find(javax.faces.context.FacesContext context)
           
 java.lang.String getFamily()
           
 java.util.List<java.lang.String> getPostScripts()
          Returns all collected posted scripts for the top of the script block.
 java.util.List<java.lang.String> getScripts()
          Returns all collected scripts for the top of the script block.
 java.util.List<java.lang.String> getScriptsOnLoad()
          Returns all collected scripts the should be executed "onload".
 boolean isInRenderedChain(FacesContextEx context)
          The component should always be rendered by Ajax requests
 boolean isRendering()
          This method checks to see if the current request is an Ajax request and whether or not the AjaxFacesContext is set to render.
 void postScript(java.lang.String newScript)
          Post a script to be rendered in the next rendering phase.
 void prepareRendering()
          Reset all collected scripts before rendering the page.
 void reset()
          Discards all collected scripts, script contributors and libraries.
 void restoreState(javax.faces.context.FacesContext context, java.lang.Object valueArray)
           
 java.lang.Object saveState(javax.faces.context.FacesContext context)
           
 
Methods inherited from class javax.faces.component.UIComponentBase
_xspCleanTransientData, _xspGetReadOnlyObj, _xspGetRendererData, _xspRemoveReadOnlyObj, _xspRemoveRendererData, _xspSetIdUnchecked, _xspSetReadOnlyObj, _xspSetRendererData, addFacesListener, broadcast, decode, encodeBegin, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientId, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getRenderer, getRendererType, getRendersChildren, getValueBinding, isRendered, isTransient, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, saveAttachedState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding
 
Methods inherited from class javax.faces.component.UIComponent
_xspGetStateId, _xspGetStateMap, _xspRestoreAttribute, _xspRestoreState, _xspSaveState, invokeOnComponent, isVisitable, markInitialState, setControlState, visitTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPONENT_TYPE

public static final java.lang.String COMPONENT_TYPE

The standard component type for this component.

See Also:
Constant Field Values

RENDERER_TYPE

public static final java.lang.String RENDERER_TYPE
See Also:
Constant Field Values

COMPONENT_FAMILY

public static final java.lang.String COMPONENT_FAMILY

The standard component family for this component.

See Also:
Constant Field Values
Constructor Detail

UIScriptCollector

public UIScriptCollector()
Constructor. Allocates buffers to store scripts, script contributors and libraries.

Method Detail

isInRenderedChain

public boolean isInRenderedChain(FacesContextEx context)
The component should always be rendered by Ajax requests

Specified by:
isInRenderedChain in interface com.ibm.xsp.ajax.AjaxPartialRefresh

addScriptOnce

public void addScriptOnce(java.lang.String newScript)
Adds a new script for the bottom of the script block, making sure the exact same script wasn't already added.

Parameters:
newScript - new script to add

addScriptOnce

public void addScriptOnce(java.lang.String newScript,
                          boolean force)

addScript

public void addScript(java.lang.String newScript)
Adds a new script for the bottom of the script block.

Parameters:
newScript - new script to add

addScript

public void addScript(java.lang.String newScript,
                      boolean force)

addScriptOnLoad

public void addScriptOnLoad(java.lang.String newScript)
Adds a new script that should be executed on load

Parameters:
newScript - new script to add

addScriptOnLoad

public void addScriptOnLoad(java.lang.String newScript,
                            boolean force)

postScript

public void postScript(java.lang.String newScript)
Post a script to be rendered in the next rendering phase. Note that this script will be rendered regardless of the current component being rendered.

Parameters:
newScript - new script to render when the page will be rendered

getFamily

public java.lang.String getFamily()
Specified by:
getFamily in class javax.faces.component.UIComponent

getScripts

public java.util.List<java.lang.String> getScripts()
Returns all collected scripts for the top of the script block. May be null.

Returns:
collected scripts

getScriptsOnLoad

public java.util.List<java.lang.String> getScriptsOnLoad()
Returns all collected scripts the should be executed "onload". May be null.

Returns:
collected scripts

getPostScripts

public java.util.List<java.lang.String> getPostScripts()
Returns all collected posted scripts for the top of the script block. May be null.

Returns:
collected scripts

prepareRendering

public void prepareRendering()
Reset all collected scripts before rendering the page. Resets buffers to zero length.


reset

public void reset()
Discards all collected scripts, script contributors and libraries. Resets buffers to zero length.


find

public static UIScriptCollector find()
Find the UIScriptCollector associated with the current page. This depends on FacesContext.getCurrentInstance().

Returns:
UIScriptCollector that was found.

find

public static UIScriptCollector find(javax.faces.context.FacesContext context)
Since:
8.5.3

saveState

public java.lang.Object saveState(javax.faces.context.FacesContext context)
Specified by:
saveState in interface javax.faces.component.StateHolder
Overrides:
saveState in class javax.faces.component.UIComponentBase

restoreState

public void restoreState(javax.faces.context.FacesContext context,
                         java.lang.Object valueArray)
Specified by:
restoreState in interface javax.faces.component.StateHolder
Overrides:
restoreState in class javax.faces.component.UIComponentBase

isRendering

public boolean isRendering()
This method checks to see if the current request is an Ajax request and whether or not the AjaxFacesContext is set to render. If the AjaxFacesContext has rendering set to true then the component that is being process at that time will be rendered to the page. If the component is being re-rendered to the page then so too must its javaScript. So this indicates whether or not the scriptCollector should add the script for the current component.

Returns:
boolean whether or not to add script blocks to the page