com.ibm.xsp.util
Class FacesUtil

java.lang.Object
  extended by com.ibm.xsp.util.FacesUtil

public class FacesUtil
extends java.lang.Object

This class provides various utility methods.


Field Summary
static java.lang.String DATASOURCE
          Deprecated. Use DataPublisher.DATASOURCE instead
static java.lang.String DEFAULT_DATASOURCE
           
static java.lang.String HIDDEN_FIELD_ID
           
static java.lang.String RESTORE_ROOT
           
 
Constructor Summary
FacesUtil()
           
 
Method Summary
static void addErrorMessage(java.lang.String summary, java.lang.String detail)
          Add an error FacesMessage to the current context.
static void addMessage(javax.faces.context.FacesContext context, javax.faces.application.FacesMessage.Severity severity, java.lang.String clientId, java.lang.String summary, java.lang.String detail)
          Add a FacesMessage to the specified context.
static void addMessage(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, javax.faces.application.FacesMessage.Severity severity, java.lang.String summary, java.lang.String detail)
          Add a FacesMessage to the specified context.
static void addMessage(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String summary, java.lang.Throwable t)
          Add a FacesMessage to the specified context.
static void addMessage(javax.faces.application.FacesMessage.Severity severity, java.lang.String summary, java.lang.String detail)
          Add a FacesMessage to the specified context.
static java.util.List<java.lang.String> calculateBundleNames(java.lang.String baseName, java.util.Locale locale)
          Calculate bundle names to be loaded
static boolean canSerializeObject(java.lang.Object data)
          Returns true if this data can be saved using objectToSerializable.
static void checkComponentIds(javax.faces.component.UIViewRoot viewRoot, javax.faces.component.UIComponent base)
          Recursively set unique ids for every component starting at the specified one.
static void checkForNestedForms(java.lang.String viewId, javax.faces.component.UIComponent component, boolean hasParentForm)
          Check for nested forms
static void checkForNonSelectChildren(javax.faces.component.UIComponent component)
          Throw an exception if any children are invalid
static boolean containsForm(javax.faces.component.UIComponent component)
          Check if this component is a form or if it contains one
static java.lang.String convertValue(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Format the value of a component.
static java.lang.String createId()
          Utility method for generating a unique ID.
static javax.faces.component.UIComponent findChildComponent(javax.faces.component.UIComponent component, java.lang.String id)
          Return the component with the specified id.
static javax.faces.component.UIComponent findComponentWithFullId(javax.faces.component.UIViewRoot root, java.lang.String id)
          Return the UIComponent with the specified id, starting from the root.
static javax.faces.component.UIComponent findRestoreComponent(javax.faces.context.FacesContext context, java.lang.String restoreId)
           
static javax.faces.component.UIComponent getComponentFor(javax.faces.component.UIComponent start, java.lang.String id)
          Return the UIComponent with the specified id, starting from a particular component.
static javax.faces.convert.Converter getConverterForClass(java.lang.Class<?> clazz)
          Create a converter for the specified class
static javax.faces.component.UIForm getForm(javax.faces.component.UIComponent component)
          Return the parent UIForm component for the specified component.
static java.lang.String getFullId(javax.faces.component.UIComponent c)
          Get the full id of a component.
static java.lang.String getHiddenExecId()
           
static java.lang.String getHiddenExecValue(javax.faces.context.FacesContext context)
           
static java.lang.String getHiddenFieldId()
          Gets the id of the form's hidden field containing the ID of the control that submits the event.
static java.lang.String getHiddenFieldValue(javax.faces.context.FacesContext context)
           
static javax.faces.lifecycle.Lifecycle getLifecycle(javax.faces.context.FacesContext context)
          Return the Lifecycle for the specified FacesContext.
static javax.faces.component.NamingContainer getNamingContainer(javax.faces.component.UIComponent component)
          Find the parent NamingContainer for the specified component.
static javax.faces.component.NamingContainer getNamingContainer(javax.faces.component.UIComponent component, int skip)
          Find the parent NamingContainer for the specified component skipping the specified number of naming containers.
static java.lang.String getRealViewId(java.lang.String viewId)
          Perform any required transformation of the view id
static javax.faces.render.Renderer getRenderer(javax.faces.context.FacesContext context, java.lang.String family, java.lang.String rendererType)
          Return the renderer associated with this component or null if there is none.
static javax.faces.render.Renderer getRendererAs(javax.faces.render.Renderer renderer, java.lang.Class<?> toImplement)
          Used to find whether the renderer or any of it's delegates implements a certain interface, and if so returns the renderer or delegate.
static java.lang.Object getRequestObject(javax.faces.context.FacesContext context, java.lang.String name)
          Return the named object from the request map.
static java.lang.Object getRequestObject(java.lang.String name)
          Return the named object from the request map.
static java.lang.Object getRequestParameter(java.lang.String name)
          Return the specified value from the request map if it exists.
static RequestParameters getRequestParameters(javax.faces.context.FacesContext ctx)
          Get the Request Customizer associayed with a FacesContext returns null if no customizer is available
static java.io.InputStream getResourceAsStream(java.lang.Class<?> clazz, java.lang.String name)
          Open an input stream to the named resource
static java.lang.String getRestoreId(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
           
static java.util.List<javax.faces.model.SelectItem> getSelectItems(javax.faces.component.UIComponent component)
          Return list of SelectItem instances associated with the specified component
static StyleKit getStyleKit(javax.faces.context.FacesContext ctx)
          Get the stylekit used by the request.
static java.lang.Object getValue(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Get the value of a component.
static javax.faces.component.UIViewRoot getViewRoot(javax.faces.component.UIComponent component)
          Return the UIViewRoot for the specified component.
static boolean hasMessage(javax.faces.context.FacesContext context, java.lang.String summary)
          Helper method to determine if the FacesContext contains a message with the specified summary.
static boolean hasStyleSheet(UIViewRootEx viewRoot)
          Return true if the view root contains any style sheet resource
static boolean hasStyleSheet(UIViewRootEx viewRoot, java.lang.String href)
          Return true if the view root contains a style sheet resource matching the href
static boolean isAbsoluteUrl(java.lang.String url)
          The following are examples of absolute URLs: http://host:80/path ftp://user:pw@host:port/path news:a.news.group file:/c:/config.sys mailto:alasdair@domain.tld This method does not provide a comprehensive test for all URL cases, but should suffice for most.
static boolean isCancelled(java.lang.Object value)
          Static method to return true if the specified value indicates the operation been canceled.
static boolean isChecked(java.lang.Object value)
          Return the checked state of the submitted value
static boolean isClientId(javax.faces.context.FacesContext context, java.lang.String id)
          Check if an id is a client id
static boolean isClientIdChildOf(FacesContextEx context, javax.faces.component.UIComponent component, java.lang.String targetId)
          Check if a component is a child of another, based on its client id.
static boolean isComponentReadOnly(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Test if the specified component should be in a read-only state.
static boolean isDecodeable(javax.faces.component.UIComponent component)
          Return true if this component can be decoded
static boolean isDuplicateMessage(javax.faces.application.FacesMessage.Severity severity, java.lang.String summary, java.lang.String detail, javax.faces.application.FacesMessage message)
           
static boolean isEditable(javax.faces.component.UIComponent component)
          Return true if this component is editable
static java.lang.String makeUrlAbsolute(javax.faces.context.FacesContext context, java.lang.String path)
           
static javax.faces.component.UIForm needForm(javax.faces.component.UIComponent component)
          Return the parent UIForm of the specified component throws exception otherwise
static java.lang.String normalizeLinkForBots(javax.faces.context.FacesContext context, java.lang.String href)
          Check if the request is coming from a search bot using the User-Agent header, in this case, checks if the content parameter is present in the request, if so, the # in the url, if present, it will be transformed in ? or & if the ? is already present in the url.
static java.lang.String normalizePageName(javax.faces.context.FacesContext context, java.lang.String name)
          Normalize the page name if it is a relative page.
static java.lang.Object objectFromSerializable(javax.faces.context.FacesContext context, java.lang.Object serForm)
           
static java.lang.Object objectFromSerializable(javax.faces.context.FacesContext context, javax.faces.component.UIComponent src, java.lang.Object serForm)
           
static java.lang.Object objectToSerializable(javax.faces.context.FacesContext context, java.lang.Object data)
          Utility method for serializing data.
static java.util.List<?> removeNonSelectItemChildren(javax.faces.component.UIComponent component)
          Remove any children of the component which are not UISelectItem or UISelectItems instances
static void renderChildren(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Render the children of a specified component
static void renderComponent(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Render the specified component and its children
static java.lang.Object resolveRequestMapVariable(javax.faces.context.FacesContext context, java.lang.String name)
           
static java.lang.Object resolveVariable(javax.faces.context.FacesContext context, java.lang.String name)
          Resolve the named variable
static void restoreNonSelectItemChildren(javax.faces.component.UIComponent component, java.util.List<?> removed)
          Restore any children of the component which are not UISelectItem or UISelectItems instances
static boolean save(javax.faces.context.FacesContext context, DataSource dataSource, boolean removeFromManager)
          Save the specified component data if it's is not read only
static boolean save(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, boolean removeFromManager)
          Save all data associated with the specified component and it's children
static void saveViewState(javax.faces.context.FacesContext context)
          Save the state of the view if it requires it.
static void serviceFacesRequest(com.ibm.xsp.controller.FacesController controller, java.lang.Object request, java.lang.Object response, java.lang.Object containerContext, javax.faces.component.UIViewRoot viewRoot)
          Execute the lifecycle and render the response for the specified request.
static void setRestoreRoot(javax.faces.context.FacesContext context, javax.faces.component.UIViewRoot viewRoot)
           
static java.lang.String toString(javax.faces.component.UIComponent component)
          Return a string representation of the specified component tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DATASOURCE

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

DATASOURCE

public static final java.lang.String DATASOURCE
Deprecated. Use DataPublisher.DATASOURCE instead
See Also:
Constant Field Values

HIDDEN_FIELD_ID

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

RESTORE_ROOT

public static final java.lang.String RESTORE_ROOT
See Also:
Constant Field Values
Constructor Detail

FacesUtil

public FacesUtil()
Method Detail

serviceFacesRequest

public static void serviceFacesRequest(com.ibm.xsp.controller.FacesController controller,
                                       java.lang.Object request,
                                       java.lang.Object response,
                                       java.lang.Object containerContext,
                                       javax.faces.component.UIViewRoot viewRoot)
Execute the lifecycle and render the response for the specified request.

Parameters:
controller -
request -
response -
viewRoot -

getRealViewId

public static java.lang.String getRealViewId(java.lang.String viewId)
Perform any required transformation of the view id


getFullId

public static java.lang.String getFullId(javax.faces.component.UIComponent c)
Get the full id of a component. The full id of a component comprises its own id and the ids of its parents that are naming containers. This allows a component to be uniquely identified in a hierarchy.


getForm

public static javax.faces.component.UIForm getForm(javax.faces.component.UIComponent component)
Return the parent UIForm component for the specified component.


needForm

public static javax.faces.component.UIForm needForm(javax.faces.component.UIComponent component)
Return the parent UIForm of the specified component throws exception otherwise

Throws:
javax.faces.FacesException

isClientId

public static boolean isClientId(javax.faces.context.FacesContext context,
                                 java.lang.String id)
Check if an id is a client id


findComponentWithFullId

public static javax.faces.component.UIComponent findComponentWithFullId(javax.faces.component.UIViewRoot root,
                                                                        java.lang.String id)
Return the UIComponent with the specified id, starting from the root. This functions stops at the first component with this id, or full id. The full id of a component is comprised of its own id, plus the ids of its parents that are naming containers. See FacesUtil#getFullId.

Parameters:
root - the root component of the page to start from
id - th id (or full id) of the component top search
Returns:
the component found, null if none

findChildComponent

public static javax.faces.component.UIComponent findChildComponent(javax.faces.component.UIComponent component,
                                                                   java.lang.String id)
Return the component with the specified id.


getComponentFor

public static javax.faces.component.UIComponent getComponentFor(javax.faces.component.UIComponent start,
                                                                java.lang.String id)
Return the UIComponent with the specified id, starting from a particular component. SPR#MKEE86YD5L Also search for components that are within facets.


isClientIdChildOf

public static boolean isClientIdChildOf(FacesContextEx context,
                                        javax.faces.component.UIComponent component,
                                        java.lang.String targetId)
Check if a component is a child of another, based on its client id.

Parameters:
context -
component -
Returns:

getViewRoot

public static javax.faces.component.UIViewRoot getViewRoot(javax.faces.component.UIComponent component)
Return the UIViewRoot for the specified component.


getLifecycle

public static javax.faces.lifecycle.Lifecycle getLifecycle(javax.faces.context.FacesContext context)
Return the Lifecycle for the specified FacesContext.


getNamingContainer

public static javax.faces.component.NamingContainer getNamingContainer(javax.faces.component.UIComponent component,
                                                                       int skip)
Find the parent NamingContainer for the specified component skipping the specified number of naming containers.


getNamingContainer

public static javax.faces.component.NamingContainer getNamingContainer(javax.faces.component.UIComponent component)
Find the parent NamingContainer for the specified component.


isEditable

public static boolean isEditable(javax.faces.component.UIComponent component)
Return true if this component is editable


save

public static boolean save(javax.faces.context.FacesContext context,
                           javax.faces.component.UIComponent component,
                           boolean removeFromManager)
Save all data associated with the specified component and it's children


save

public static boolean save(javax.faces.context.FacesContext context,
                           DataSource dataSource,
                           boolean removeFromManager)
Save the specified component data if it's is not read only


checkForNestedForms

public static void checkForNestedForms(java.lang.String viewId,
                                       javax.faces.component.UIComponent component,
                                       boolean hasParentForm)
Check for nested forms


containsForm

public static boolean containsForm(javax.faces.component.UIComponent component)
Check if this component is a form or if it contains one


checkComponentIds

public static void checkComponentIds(javax.faces.component.UIViewRoot viewRoot,
                                     javax.faces.component.UIComponent base)
Recursively set unique ids for every component starting at the specified one.


getRenderer

public static javax.faces.render.Renderer getRenderer(javax.faces.context.FacesContext context,
                                                      java.lang.String family,
                                                      java.lang.String rendererType)
Return the renderer associated with this component or null if there is none.


getRequestParameter

public static java.lang.Object getRequestParameter(java.lang.String name)
Return the specified value from the request map if it exists.


getSelectItems

public static java.util.List<javax.faces.model.SelectItem> getSelectItems(javax.faces.component.UIComponent component)
Return list of SelectItem instances associated with the specified component


removeNonSelectItemChildren

public static java.util.List<?> removeNonSelectItemChildren(javax.faces.component.UIComponent component)
Remove any children of the component which are not UISelectItem or UISelectItems instances


restoreNonSelectItemChildren

public static void restoreNonSelectItemChildren(javax.faces.component.UIComponent component,
                                                java.util.List<?> removed)
Restore any children of the component which are not UISelectItem or UISelectItems instances


toString

public static java.lang.String toString(javax.faces.component.UIComponent component)
Return a string representation of the specified component tree.


renderComponent

public static void renderComponent(javax.faces.context.FacesContext context,
                                   javax.faces.component.UIComponent component)
                            throws java.io.IOException
Render the specified component and its children

Throws:
java.io.IOException

renderChildren

public static void renderChildren(javax.faces.context.FacesContext context,
                                  javax.faces.component.UIComponent component)
                           throws java.io.IOException
Render the children of a specified component

Throws:
java.io.IOException

hasStyleSheet

public static boolean hasStyleSheet(UIViewRootEx viewRoot,
                                    java.lang.String href)
Return true if the view root contains a style sheet resource matching the href


hasStyleSheet

public static boolean hasStyleSheet(UIViewRootEx viewRoot)
Return true if the view root contains any style sheet resource


hasMessage

public static boolean hasMessage(javax.faces.context.FacesContext context,
                                 java.lang.String summary)
Helper method to determine if the FacesContext contains a message with the specified summary.


isCancelled

public static boolean isCancelled(java.lang.Object value)
Static method to return true if the specified value indicates the operation been canceled.


addErrorMessage

public static void addErrorMessage(java.lang.String summary,
                                   java.lang.String detail)
Add an error FacesMessage to the current context.


addMessage

public static void addMessage(javax.faces.context.FacesContext context,
                              javax.faces.component.UIComponent component,
                              java.lang.String summary,
                              java.lang.Throwable t)
Add a FacesMessage to the specified context.


addMessage

public static void addMessage(javax.faces.application.FacesMessage.Severity severity,
                              java.lang.String summary,
                              java.lang.String detail)
Add a FacesMessage to the specified context.


addMessage

public static void addMessage(javax.faces.context.FacesContext context,
                              javax.faces.component.UIComponent component,
                              javax.faces.application.FacesMessage.Severity severity,
                              java.lang.String summary,
                              java.lang.String detail)
Add a FacesMessage to the specified context.


addMessage

public static void addMessage(javax.faces.context.FacesContext context,
                              javax.faces.application.FacesMessage.Severity severity,
                              java.lang.String clientId,
                              java.lang.String summary,
                              java.lang.String detail)
Add a FacesMessage to the specified context.


isDuplicateMessage

public static boolean isDuplicateMessage(javax.faces.application.FacesMessage.Severity severity,
                                         java.lang.String summary,
                                         java.lang.String detail,
                                         javax.faces.application.FacesMessage message)

resolveVariable

public static java.lang.Object resolveVariable(javax.faces.context.FacesContext context,
                                               java.lang.String name)
Resolve the named variable


resolveRequestMapVariable

public static java.lang.Object resolveRequestMapVariable(javax.faces.context.FacesContext context,
                                                         java.lang.String name)

isDecodeable

public static boolean isDecodeable(javax.faces.component.UIComponent component)
Return true if this component can be decoded


getValue

public static java.lang.Object getValue(javax.faces.context.FacesContext context,
                                        javax.faces.component.UIComponent component)
Get the value of a component.

Parameters:
context -
component -
Throws:
javax.faces.convert.ConverterException

convertValue

public static java.lang.String convertValue(javax.faces.context.FacesContext context,
                                            javax.faces.component.UIComponent component)
                                     throws javax.faces.convert.ConverterException
Format the value of a component.

Parameters:
context -
component -
Returns:
the converted value, with acf applied
Throws:
javax.faces.convert.ConverterException

isChecked

public static boolean isChecked(java.lang.Object value)
Return the checked state of the submitted value


getConverterForClass

public static javax.faces.convert.Converter getConverterForClass(java.lang.Class<?> clazz)
Create a converter for the specified class


getRequestObject

public static java.lang.Object getRequestObject(java.lang.String name)
Return the named object from the request map.


getRequestObject

public static java.lang.Object getRequestObject(javax.faces.context.FacesContext context,
                                                java.lang.String name)
Return the named object from the request map.


getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.Class<?> clazz,
                                                      java.lang.String name)
Open an input stream to the named resource


canSerializeObject

public static boolean canSerializeObject(java.lang.Object data)
Returns true if this data can be saved using objectToSerializable. This method should be used only in special cases; generally, implementers should know if data can be serialized. Dependence on this method may lead to strange logical errors (e.g. if a List can be serialized; its members cannot; the list is empty when passed to this method). Use of this method may impact performance.


objectToSerializable

public static java.lang.Object objectToSerializable(javax.faces.context.FacesContext context,
                                                    java.lang.Object data)
Utility method for serializing data. Supports (in order of preference): Any other conditions result in a RuntimeException.

Parameters:
context -
data - must implement Serializable or StateHolder; may be null
Returns:
serializable form or null for null argument or transient data

objectFromSerializable

public static java.lang.Object objectFromSerializable(javax.faces.context.FacesContext context,
                                                      javax.faces.component.UIComponent src,
                                                      java.lang.Object serForm)
Parameters:
context -
src -
serForm -
Returns:
the data or null if argument was null

objectFromSerializable

public static java.lang.Object objectFromSerializable(javax.faces.context.FacesContext context,
                                                      java.lang.Object serForm)

getHiddenFieldId

public static java.lang.String getHiddenFieldId()
Gets the id of the form's hidden field containing the ID of the control that submits the event.

Parameters:
context -
component -
submitAsForm -
Returns:

getHiddenFieldValue

public static java.lang.String getHiddenFieldValue(javax.faces.context.FacesContext context)

getHiddenExecId

public static java.lang.String getHiddenExecId()

getHiddenExecValue

public static java.lang.String getHiddenExecValue(javax.faces.context.FacesContext context)

createId

public static java.lang.String createId()
Utility method for generating a unique ID.

Returns:
ID String (in hexadecimal form)

getRestoreId

public static java.lang.String getRestoreId(javax.faces.context.FacesContext context,
                                            javax.faces.component.UIComponent component)

saveViewState

public static void saveViewState(javax.faces.context.FacesContext context)
Save the state of the view if it requires it.


setRestoreRoot

public static void setRestoreRoot(javax.faces.context.FacesContext context,
                                  javax.faces.component.UIViewRoot viewRoot)

findRestoreComponent

public static javax.faces.component.UIComponent findRestoreComponent(javax.faces.context.FacesContext context,
                                                                     java.lang.String restoreId)

checkForNonSelectChildren

public static void checkForNonSelectChildren(javax.faces.component.UIComponent component)
Throw an exception if any children are invalid


calculateBundleNames

public static java.util.List<java.lang.String> calculateBundleNames(java.lang.String baseName,
                                                                    java.util.Locale locale)
Calculate bundle names to be loaded


getRequestParameters

public static RequestParameters getRequestParameters(javax.faces.context.FacesContext ctx)
Get the Request Customizer associayed with a FacesContext returns null if no customizer is available


getStyleKit

public static StyleKit getStyleKit(javax.faces.context.FacesContext ctx)
Get the stylekit used by the request.

Parameters:
ctx -
Returns:

makeUrlAbsolute

public static java.lang.String makeUrlAbsolute(javax.faces.context.FacesContext context,
                                               java.lang.String path)

isAbsoluteUrl

public static boolean isAbsoluteUrl(java.lang.String url)
The following are examples of absolute URLs: This method does not provide a comprehensive test for all URL cases, but should suffice for most.

Parameters:
url - the non-null URL to test
Returns:
true if the pattern matches that of an absolute URL

normalizeLinkForBots

public static java.lang.String normalizeLinkForBots(javax.faces.context.FacesContext context,
                                                    java.lang.String href)
Check if the request is coming from a search bot using the User-Agent header, in this case, checks if the content parameter is present in the request, if so, the # in the url, if present, it will be transformed in ? or & if the ? is already present in the url.

Parameters:
context - the context of the request must be a FacesContextEx to actually perform the check, otherwise href is returned untouched
href - the href link to be modified.
Returns:
the new href if conditions apply, or the one received in input otherwise.

normalizePageName

public static java.lang.String normalizePageName(javax.faces.context.FacesContext context,
                                                 java.lang.String name)
Normalize the page name if it is a relative page. It computes the page name based on the current page path if it is a relative path.

Parameters:
context -
name -
Returns:

getRendererAs

public static javax.faces.render.Renderer getRendererAs(javax.faces.render.Renderer renderer,
                                                        java.lang.Class<?> toImplement)
Used to find whether the renderer or any of it's delegates implements a certain interface, and if so returns the renderer or delegate.

Parameters:
renderer -
toImplement -
Returns:

isComponentReadOnly

public static boolean isComponentReadOnly(javax.faces.context.FacesContext context,
                                          javax.faces.component.UIComponent component)
Test if the specified component should be in a read-only state.