Class Hierarchy All Classes All Fields and Methods
Class com.ibm.faces.component.UIScriptCollector
java.lang.Object javax.faces.component.UIComponent javax.faces.component.UIComponentBase com.ibm.faces.component.UIScriptCollectorpublic class UIScriptCollector
extends UIComponentBaseUIScriptCollector is a UIComponent that wraps other components on a JSF page.
It provides the following services:
- It collects names of JavaScript libraries that would be needed in the following SCRIPT block by the collected and contributed scripts.
Components that need a JavaScript library included in the page should call addLibrary method to have their libraries registered with the ScriptCollector.- It can create and write an include statement for a JavaScript library directly into ResponseWriter.
Components that need a JavaScript library included at certain places inside the page should call writeLibraryReference method to have their libraries included and registered with the ScriptCollector.- It collects JavaScript code from its children to be outputted after all these components are rendered.
Components that want to add JavaScript code at the end of the page should call addScript or addScriptOnce methods to have their scripts registered with the ScriptCollector. These scripts will be outputed as a part of encodeEnd phase of ScriptCollector's rendering.- It collects script contributors (classes that implement IScriptContributor) and lets them output JavaScript code after all children components are rendered.
Components that do not want to (or can't) add scripts as described in the previous paragraph, can implenent IScriptContributor interface and register themselves with the ScriptCollector. In this case their contributeScript methods will be called as a part of encodeEnd phase of ScriptCollector's rendering.- It allows event scripting by exposing preRender, postRender and decode attributes. These attributes can contain names of the methods in a Java class (code behind class, for example) that take a FacesContext parameter and return void. These methods are called at the corresponding phases of the ScriptCollector's rendering:
- preRender is called before ScriptCollector and all its children render
- postRender is called after ScriptCollector and all its children have been rendered
- decode is called when ScriptCollector is being decoded, ie the page is being submitted to the server
Tags:
Renderers: ScriptCollectorRenderer
Field Index Field Description ADD_AT_BOTTOM Constant for addScript methods. ADD_AT_TOP Constant for addScript methods. COMPONENT_FAMILY The standard component family for this component. COMPONENT_TYPE The standard component type for this component. FIND_NEAREST Scope constant for find methods. FIND_TOPMOST Scope constant for find methods.
Constructor Index Constructor Description UIScriptCollector() Constructor.
Method Index Method Description void addLibrary(String) Adds a new script library to the collection, making sure the exact same library wasn't already added. void addScript(String) Adds a new script for the bottom of the script block. void addScript(String, int) Adds a new script to the collection. void addScriptOnce(String) Adds a new script for the bottom of the script block, making sure the exact same script wasn't already added. void addScriptOnce(String, int) Adds a new script to the collection, making sure the exact same script wasn't already added. UIScriptCollector find(UIComponent) Finds the topmost component for any given UIComponent, that is passed as a parameter. UIScriptCollector find(UIComponent, int) Finds the right component for any given UIComponent, that is passed as a parameter. HashMap getContributors() Returns all registerd script contributors. MethodBinding getDecode() String getFamily() Vector getLibraries() Returns all collected libraries MethodBinding getPostRender() MethodBinding getPreRender() Vector getScriptsBottom() Returns all collected scripts for the bottom of the script block. Vector getScriptsTop() Returns all collected scripts for the top of the script block. void register(IScriptContributor, UIComponent) Registers a new script contributor. void reset() Discards all collected scripts, script contributors and libraries. void setDecode(MethodBinding) void setPostRender(MethodBinding) void setPreRender(MethodBinding) void writeLibraryReference(String, FacesContext) Writes an include statement for a script library into ResponseWriter, making sure the exact same library wasn't already included. void writeScriptOnce(String, FacesContext, boolean) Writes a Java Script into ResponseWriter, making sure the exact same script wasn't already written.
Fields
ADD_AT_BOTTOM
public static final int ADD_AT_BOTTOMConstant for addScript methods. Scripts added with ADD_AT_BOTTOM will be outputed at the bottom of the SCRIPT block, after the contributers.
ADD_AT_TOP
public static final int ADD_AT_TOPConstant for addScript methods. Scripts added with ADD_AT_TOP will be outputed at the top of the SCRIPT block, before the contributers.
COMPONENT_FAMILY
public static final java.lang.String COMPONENT_FAMILY
The standard component family for this component.
COMPONENT_TYPE
public static final java.lang.String COMPONENT_TYPE
The standard component type for this component.
FIND_NEAREST
public static final int FIND_NEARESTScope constant for find methods. Looks for the nearest parent tag.
FIND_TOPMOST
public static final int FIND_TOPMOSTScope constant for find methods. Looks for the topmost parent tag.
Constructors
UIScriptCollector
public UIScriptCollector()Constructor. Allocates buffers to store scripts, script contributors and libraries.
Methods
addLibrary
public void addLibrary(String newLib)Adds a new script library to the collection, making sure the exact same library wasn't already added.
- Parameters
- newLib - new library to add
addScript
public void addScript(String newScript)Adds a new script for the bottom of the script block.
- Parameters
- newScript - new script to add
addScript
public void addScript(String newScript, int addWhere)Adds a new script to the collection.
- Parameters
- newScript - new script to add
- addWhere - specifies where to add the script (top or bottom of the script block)
addScriptOnce
public void addScriptOnce(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(String newScript, int addWhere)Adds a new script to the collection, making sure the exact same script wasn't already added.
- Parameters
- newScript - new script to add
- addWhere - specifies where to add the script (top or bottom of the script block)
find
public static UIScriptCollector find(UIComponent component)Finds the topmost component for any given UIComponent, that is passed as a parameter.
- Parameters
- component - UIComponent to start search with.
- Returns
- that was found
- See Also
find
public static UIScriptCollector find(UIComponent component, int scope)Finds the right component for any given UIComponent, that is passed as a parameter.
In case there are multiple ScriptCollector tags on the page, it is important to be able to find the correct Collector for a component to register its scripts with. This method can find either the closest or the topmost ScriptCollector on the page.
- Parameters
- component - UIComponent to start search with.
- scope - scope for the search. This method can look either for the closest (FIND_NEAREST) or the topmost (FIND_TOPMOST).
- Returns
- that was found according to the scope parameter.
getContributors
public HashMap getContributors()Returns all registerd script contributors.
- Returns
- all contributors in component/contributor Map
getDecode
public MethodBinding getDecode()
- Returns
getFamily
public String getFamily()
getLibraries
public Vector getLibraries()Returns all collected libraries
- Returns
- Vector of strings with library names
getPostRender
public MethodBinding getPostRender()
- Returns
getPreRender
public MethodBinding getPreRender()
- Returns
getScriptsBottom
public Vector getScriptsBottom()Returns all collected scripts for the bottom of the script block.
- Returns
- collected scripts
getScriptsTop
public Vector getScriptsTop()Returns all collected scripts for the top of the script block.
- Returns
- collected scripts
register
public void register(IScriptContributor contributor, UIComponent component)Registers a new script contributor.
- Parameters
- contributor - contributor to register
- component - component for the contributor to act on
reset
public void reset()Discards all collected scripts, script contributors and libraries. Resets buffers to zero length.
setDecode
public void setDecode(MethodBinding binding)
- Parameters
- binding -
setPostRender
public void setPostRender(MethodBinding binding)
- Parameters
- binding -
setPreRender
public void setPreRender(MethodBinding binding)
- Parameters
- binding -
writeLibraryReference
public void writeLibraryReference(String newLib, FacesContext context)Writes an include statement for a script library into ResponseWriter, making sure the exact same library wasn't already included. The URL for the library is encoded for the Portal using ExternalContext#encodeResourceURL.
- Parameters
- newLib - new library to add
- context - FacesContext for the request being processed
- Throws
- IOException
writeScriptOnce
public void writeScriptOnce(String newScript, FacesContext context, boolean bWrapInScriptBlock)Writes a Java Script into ResponseWriter, making sure the exact same script wasn't already written.
- Parameters
- newScript - new script to write
- context - FacesContext for the request being processed
- Throws
- IOException
Class Hierarchy All Classes All Fields and Methods