- All Implemented Interfaces:
- javax.faces.component.NamingContainer, javax.faces.component.StateHolder
public class GlobalId
- extends javax.faces.component.UIComponentBase
- implements javax.faces.component.NamingContainer
A simple container-component that causes its child components to render a clientId value without
Important: this component works only when run in a JSF-1.2 (or later) environment. When run in
a JSF-1.1 environment it will not cause an error, but will instead act like a NamingContainer
itself, ie will add its own id to the child component's clientId.
Every JSF component has a "clientId" property; when the component is rendered, many components
output this as part of the rendered representation. In particular, when rendering HTML, many
components write an "id" attribute on their html element which contains the clientId. The clientId
is defined as being the clientId value of the nearest NamingContainer ancestor plus ":" plus the
The prefixing of the parent container's clientId is important for safely building views from
multiple files (eg using Facelets templating or JSP includes). However in some cases it is
necessary or useful to render a clientId which is just the raw id of the component without any
naming-container prefix; this component can be used to do that simply by adding an instance of
this type as an ancestor of the problem components. This works for all JSF components,
not just Tomahawk ones.
Use of this component should be a "last resort"; having clientIds which contain the id of the ancestor
NamingContainer is important and useful behaviour. It allows a view to be built from multiple different
files (using facelets templating or jsp includes); without this feature, component ids would need to be
very carefully managed to ensure the same id was not used in two places. In addition, it would not be
possible to include the same page fragment twice.
Ids are sometimes used by Cascading Style Sheets to address individual components, and JSF compound
ids are not usable by CSS. However wherever possible use a style class to select the component
rather than using this component to assign a "global" id.
clicked item (document.getById). Here, the onclick handler method can be passed the id of the clicked
object, and some simple string manipulation can then compute the correct clientId for the target
component, rather than using this component to assign a "global" id to the component to be accessed.
This component is similar to the "forceId" attribute available on many Tomahawk components. Unlike
the forceId attribute this (a) can be used with all components, not just Tomahawk ones, and (b)
applies to all its child components.
Note that since JSF1.2 forms have the property prefixId which can be set to false to make a UIForm
act as if it is not a NamingContainer. This is a good idea; the form component should probably
never have been a NamingContainer, and disabling this has no significant negative effects.
|Fields inherited from class javax.faces.component.UIComponent
|Fields inherited from interface javax.faces.component.NamingContainer
|Methods inherited from class javax.faces.component.UIComponentBase
addFacesListener, broadcast, decode, encodeBegin, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientId, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getRenderer, getRendererType, getRendersChildren, getValueBinding, invokeOnComponent, isRendered, isTransient, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding
|Methods inherited from class javax.faces.component.UIComponent
encodeAll, getValueExpression, setValueExpression
|Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static final java.lang.String COMPONENT_FAMILY
- See Also:
- Constant Field Values
public static final java.lang.String COMPONENT_TYPE
- See Also:
- Constant Field Values
public java.lang.String getFamily()
- Specified by:
getFamily in class
public java.lang.String getContainerClientId(javax.faces.context.FacesContext facesContext)
getContainerClientId in class
Copyright © 2011 The Apache Software Foundation. All Rights Reserved.