| Method from javax.faces.component.UIComponentBase Detail: |
protected void addFacesListener(FacesListener listener) {
if (listener == null) {
throw new NullPointerException();
}
if (listeners == null) {
//noinspection CollectionWithoutInitialCapacity
listeners = new ArrayList< FacesListener >();
}
listeners.add(listener);
}
Add the specified FacesListener to the set of listeners
registered to receive event notifications from this UIComponent .
It is expected that UIComponent classes acting as event sources
will have corresponding typesafe APIs for registering listeners of the
required type, and the implementation of those registration methods
will delegate to this method. For example:
public class FooEvent extends FacesEvent {
...
protected boolean isAppropriateListener(FacesListener listener) {
return (listener instanceof FooListener);
}
protected void processListener(FacesListener listener) {
((FooListener) listener).processFoo(this);
}
...
}
public interface FooListener extends FacesListener {
public void processFoo(FooEvent event);
}
public class FooComponent extends UIComponentBase {
...
public void addFooListener(FooListener listener) {
addFacesListener(listener);
}
public void removeFooListener(FooListener listener) {
removeFacesListener(listener);
}
...
}
|
public void broadcast(FacesEvent event) throws AbortProcessingException {
if (event == null) {
throw new NullPointerException();
}
if (listeners == null) {
return;
}
Iterator< FacesListener > iter = listeners.iterator();
while (iter.hasNext()) {
FacesListener listener = iter.next();
if (event.isAppropriateListener(listener)) {
event.processListener(listener);
}
}
}
|
public void decode(FacesContext context) {
if (context == null) {
throw new NullPointerException();
}
String rendererType = getRendererType();
if (rendererType != null) {
Renderer renderer = this.getRenderer(context);
if (renderer != null) {
renderer.decode(context, this);
}else {
// TODO: i18n
log.fine("Can't get Renderer for type " + rendererType);
}
}
}
|
public void encodeBegin(FacesContext context) throws IOException {
if (context == null) {
throw new NullPointerException();
}
if (!isRendered()) {
return;
}
String rendererType = getRendererType();
if (rendererType != null) {
Renderer renderer = this.getRenderer(context);
if (renderer != null) {
renderer.encodeBegin(context, this);
} else {
// TODO: i18n
log.fine("Can't get Renderer for type " + rendererType);
}
}
}
|
public void encodeChildren(FacesContext context) throws IOException {
if (context == null) {
throw new NullPointerException();
}
if (!isRendered()) {
return;
}
String rendererType = getRendererType();
if (rendererType != null) {
Renderer renderer = this.getRenderer(context);
if (renderer != null) {
renderer.encodeChildren(context, this);
} else {
// We've already logged for this component
}
}
}
|
public void encodeEnd(FacesContext context) throws IOException {
if (context == null) {
throw new NullPointerException();
}
if (!isRendered()) {
return;
}
String rendererType = getRendererType();
if (rendererType != null) {
Renderer renderer = this.getRenderer(context);
if (renderer != null) {
renderer.encodeEnd(context, this);
} else {
// We've already logged for this component
}
}
}
|
public UIComponent findComponent(String expr) {
if (expr == null) {
throw new NullPointerException();
}
if (expr.length() == 0) {
// if an empty value is provided, fail fast.
throw new IllegalArgumentException("\"\"");
}
// Identify the base component from which we will perform our search
UIComponent base = this;
if (expr.charAt(0) == NamingContainer.SEPARATOR_CHAR) {
// Absolute searches start at the root of the tree
while (base.getParent() != null) {
base = base.getParent();
}
// Treat remainder of the expression as relative
expr = expr.substring(1);
} else {
// Relative expressions start at the closest NamingContainer or root
while (base.getParent() != null) {
if (base instanceof NamingContainer) {
break;
}
base = base.getParent();
}
}
// Evaluate the search expression (now guaranteed to be relative)
UIComponent result = null;
String[] segments = expr.split(SEPARATOR_STRING);
for (int i = 0, length = (segments.length - 1);
i < segments.length;
i++, length--) {
result = findComponent(base, segments[i], (i == 0));
// the first element of the expression may match base.id
// (vs. a child if of base)
if (i == 0 && result == null &&
segments[i].equals(base.getId())) {
result = base;
}
if (result != null && (!(result instanceof NamingContainer)) && length > 0) {
throw new IllegalArgumentException(segments[i]);
}
if (result == null) {
break;
}
base = result;
}
// Return the final result of our search
return (result);
}
|
public Map getAttributes() {
if (attributes == null) {
attributes = new AttributesMap(this);
}
return (attributes);
}
|
public int getChildCount() {
if (children != null) {
return (children.size());
} else {
return (0);
}
}
|
public List getChildren() {
if (children == null) {
children = new ChildrenList(this);
}
return (children);
}
|
public String getClientId(FacesContext context) {
if (context == null) {
throw new NullPointerException();
}
// if the clientId is not yet set
if (this.clientId == null) {
UIComponent parent = this.getNamingContainer();
String parentId = null;
// give the parent the opportunity to first
// grab a unique clientId
if (parent != null) {
parentId = parent.getContainerClientId(context);
}
// now resolve our own client id
this.clientId = getId();
if (this.clientId == null) {
setId(context.getViewRoot().createUniqueId());
this.clientId = getId();
}
if (parentId != null) {
StringBuilder idBuilder =
new StringBuilder(parentId.length()
+ 1
+ this.clientId.length());
this.clientId = idBuilder.append(parentId)
.append(NamingContainer.SEPARATOR_CHAR)
.append(this.clientId).toString();
}
// allow the renderer to convert the clientId
Renderer renderer = this.getRenderer(context);
if (renderer != null) {
this.clientId = renderer.convertClientId(context, this.clientId);
}
}
return this.clientId;
}
|
Map getDescriptorMap() {
return pdMap;
}
|
protected FacesContext getFacesContext() {
// PENDING(edburns): we can't use the cache ivar because we
// don't always know when to clear it. For example, in the
// "save state in server" case, the UIComponent instances stick
// around between requests, yielding stale facesContext
// references. If there was some way to clear the facesContext
// cache ivar for each node in the tree *after* the
// render-response phase, then we could keep a cache ivar. As
// it is now, we must always use the Thread Local Storage
// solution.
return FacesContext.getCurrentInstance();
}
|
protected FacesListener[] getFacesListeners(Class clazz) {
if (clazz == null) {
throw new NullPointerException();
}
if (!FacesListener.class.isAssignableFrom(clazz)) {
throw new IllegalArgumentException();
}
if (listeners == null) {
return ((FacesListener[])
java.lang.reflect.Array.newInstance(clazz, 0));
}
//noinspection CollectionWithoutInitialCapacity
List< FacesListener > results = new ArrayList< FacesListener >();
Iterator< FacesListener > items = listeners.iterator();
while (items.hasNext()) {
FacesListener item = items.next();
if (((Class< ? >)clazz).isAssignableFrom(item.getClass())) {
results.add(item);
}
}
return (results.toArray
((FacesListener []) java.lang.reflect.Array.newInstance(clazz,
results.size())));
}
|
public UIComponent getFacet(String name) {
if (facets != null) {
return (facets.get(name));
} else {
return (null);
}
}
|
public int getFacetCount() {
if (facets != null) {
return (facets.size());
} else {
return (0);
}
}
|
public Map getFacets() {
if (facets == null) {
facets = new FacetsMap(this);
}
return (facets);
}
|
public Iterator getFacetsAndChildren() {
Iterator< UIComponent > result;
int childCount = this.getChildCount(),
facetCount = this.getFacetCount();
// If there are neither facets nor children
if (0 == childCount && 0 == facetCount) {
result = EMPTY_ITERATOR;
}
// If there are only facets and no children
else if (0 == childCount) {
Collection< UIComponent > unmodifiable =
Collections.unmodifiableCollection(getFacets().values());
result = unmodifiable.iterator();
}
// If there are only children and no facets
else if (0 == facetCount) {
List< UIComponent > unmodifiable =
Collections.unmodifiableList(getChildren());
result = unmodifiable.iterator();
}
// If there are both children and facets
else {
result = new FacetsAndChildrenIterator(this);
}
return result;
}
|
public String getId() {
return (id);
}
|
public UIComponent getParent() {
return (this.parent);
}
|
protected Renderer getRenderer(FacesContext context) {
String rendererType = getRendererType();
Renderer result = null;
if (rendererType != null) {
result = context.getRenderKit().getRenderer(getFamily(),
rendererType);
if (null == result) {
if (log.isLoggable(Level.FINE)) {
// PENDING(edburns): I18N
log.fine("Can't get Renderer for type " + rendererType);
}
}
} else {
if (log.isLoggable(Level.FINE)) {
String id = this.getId();
id = (null != id) ? id : this.getClass().getName();
// PENDING(edburns): I18N
log.fine("No renderer-type for component " + id);
}
}
return result;
}
|
public String getRendererType() {
if (this.rendererType != null) {
return (this.rendererType);
}
ValueExpression ve = getValueExpression("rendererType");
if (ve != null) {
try {
return ((String) ve.getValue(getFacesContext().getELContext()));
}
catch (ELException e) {
throw new FacesException(e);
}
} else {
return (null);
}
}
|
public boolean getRendersChildren() {
boolean result = false;
Renderer renderer;
if (getRendererType() != null) {
if (null !=
(renderer = getRenderer(getFacesContext()))) {
result = renderer.getRendersChildren();
}
}
return result;
}
|
public ValueBinding getValueBinding(String name) {
if (name == null) {
throw new NullPointerException();
}
ValueBinding result = null;
ValueExpression ve;
if (null != (ve = getValueExpression(name))) {
// if the ValueExpression is an instance of our private
// wrapper class.
if (ve.getClass().equals(ValueExpressionValueBindingAdapter.class)) {
result = ((ValueExpressionValueBindingAdapter)ve).getWrapped();
}
else {
// otherwise, this is a real ValueExpression. Wrap it
// in a ValueBinding.
result = new ValueBindingValueExpressionAdapter(ve);
}
}
return result;
} Deprecated! This - has been replaced by #getValueExpression .
|
public boolean invokeOnComponent(FacesContext context,
String clientId,
ContextCallback callback) throws FacesException {
return super.invokeOnComponent(context, clientId, callback);
}
|
public boolean isRendered() {
if (renderedSet) {
return (rendered);
}
ValueExpression ve = getValueExpression("rendered");
if (ve != null) {
try {
return (!Boolean.FALSE.equals(ve.getValue(getFacesContext().getELContext())));
}
catch (ELException e) {
throw new FacesException(e);
}
} else {
return (this.rendered);
}
}
|
public boolean isTransient() {
return (this.transientFlag);
}
|
public void processDecodes(FacesContext context) {
if (context == null) {
throw new NullPointerException();
}
// Skip processing if our rendered flag is false
if (!isRendered()) {
return;
}
// Process all facets and children of this component
Iterator kids = getFacetsAndChildren();
while (kids.hasNext()) {
UIComponent kid = (UIComponent) kids.next();
kid.processDecodes(context);
}
// Process this component itself
try {
decode(context);
} catch (RuntimeException e) {
context.renderResponse();
throw e;
}
}
|
public void processRestoreState(FacesContext context,
Object state) {
if (context == null) {
throw new NullPointerException();
}
Object [] stateStruct = (Object []) state;
Object [] childState = (Object []) stateStruct[CHILD_STATE];
// Process this component itself
restoreState(context, stateStruct[MY_STATE]);
int i = 0;
// Process all the children of this component
if (this.getChildCount() > 0) {
Iterator kids = getChildren().iterator();
while (kids.hasNext()) {
UIComponent kid = (UIComponent) kids.next();
if (kid.isTransient()) {
continue;
}
Object currentState = childState[i++];
if (currentState == null) {
continue;
}
kid.processRestoreState(context, currentState);
}
}
// process all of the facets of this component
if (this.getFacetCount() > 0) {
int facetsSize = getFacets().size();
int j = 0;
Object[] facetSaveState;
String facetName;
UIComponent facet;
Object facetState;
while (j < facetsSize) {
if (null != (facetSaveState = (Object[])childState[i++])) {
facetName = (String) facetSaveState[0];
facetState = facetSaveState[1];
facet = getFacets().get(facetName);
facet.processRestoreState(context, facetState);
}
++j;
}
}
}
|
public Object processSaveState(FacesContext context) {
if (context == null) {
throw new NullPointerException();
}
if (this.isTransient()) {
return null;
}
Object [] stateStruct = new Object[2];
Object [] childState = EMPTY_ARRAY;
// Process this component itself
stateStruct[MY_STATE] = saveState(context);
// determine if we have any children to store
int count = this.getChildCount() + this.getFacetCount();
if (count > 0) {
// this arraylist will store state
List< Object > stateList = new ArrayList< Object >(count);
// if we have children, add them to the stateList
if (this.getChildCount() > 0) {
Iterator kids = getChildren().iterator();
UIComponent kid;
while (kids.hasNext()) {
kid = (UIComponent) kids.next();
if (!kid.isTransient()) {
stateList.add(kid.processSaveState(context));
}
}
}
// if we have facets, add them to the stateList
if (this.getFacetCount() > 0) {
Iterator myFacets = getFacets().entrySet().iterator();
UIComponent facet;
Object facetState;
Object[] facetSaveState;
Map.Entry entry;
while (myFacets.hasNext()) {
entry = (Map.Entry) myFacets.next();
facet = (UIComponent) entry.getValue();
if (!facet.isTransient()) {
facetState = facet.processSaveState(context);
facetSaveState = new Object[2];
facetSaveState[0] = entry.getKey();
facetSaveState[1] = facetState;
stateList.add(facetSaveState);
}
}
}
// finally, capture the stateList and replace the original,
// EMPTY_OBJECT_ARRAY Object array
childState = stateList.toArray();
}
stateStruct[CHILD_STATE] = childState;
return stateStruct;
}
|
public void processUpdates(FacesContext context) {
if (context == null) {
throw new NullPointerException();
}
// Skip processing if our rendered flag is false
if (!isRendered()) {
return;
}
// Process all facets and children of this component
Iterator kids = getFacetsAndChildren();
while (kids.hasNext()) {
UIComponent kid = (UIComponent) kids.next();
kid.processUpdates(context);
}
}
|
public void processValidators(FacesContext context) {
if (context == null) {
throw new NullPointerException();
}
// Skip processing if our rendered flag is false
if (!isRendered()) {
return;
}
// Process all the facets and children of this component
Iterator kids = getFacetsAndChildren();
while (kids.hasNext()) {
UIComponent kid = (UIComponent) kids.next();
kid.processValidators(context);
}
}
|
public void queueEvent(FacesEvent event) {
if (event == null) {
throw new NullPointerException();
}
UIComponent parent = getParent();
if (parent == null) {
throw new IllegalStateException();
} else {
parent.queueEvent(event);
}
}
|
protected void removeFacesListener(FacesListener listener) {
if (listener == null) {
throw new NullPointerException();
}
if (listeners == null) {
return;
}
listeners.remove(listener);
}
Remove the specified FacesListener from the set of listeners
registered to receive event notifications from this UIComponent .
|
public static Object restoreAttachedState(FacesContext context,
Object stateObj) throws IllegalStateException {
if (null == context) {
throw new NullPointerException();
}
if (null == stateObj) {
return null;
}
Object result;
if (stateObj instanceof List) {
List stateList = (List) stateObj;
List< Object > retList = new ArrayList< Object >(stateList.size());
for (Object item : stateList) {
try {
retList.add(((StateHolderSaver) item).restore(context));
} catch (ClassCastException cce) {
throw new IllegalStateException("Unknown object type");
}
}
result = retList;
} else if (stateObj instanceof StateHolderSaver) {
StateHolderSaver saver = (StateHolderSaver) stateObj;
result = saver.restore(context);
} else {
throw new IllegalStateException("Unknown object type");
}
return result;
}
|
public void restoreState(FacesContext context,
Object state) {
values = (Object[]) state;
// we need to get the map that knows how to handle attribute/property
// transparency before we restore its values.
if (values[0] != null) {
attributes = new AttributesMap(this,
(HashMap) TypedCollections.dynamicallyCastMap((Map) values[0],
String.class,
Object.class));
}
bindings = restoreBindingsState(context, values[1]);
clientId = (String) values[2];
id = (String) values[3];
rendered = ((Boolean) values[4]).booleanValue();
renderedSet = ((Boolean) values[5]).booleanValue();
rendererType = (String) values[6];
List< FacesListener > restoredListeners;
if (null != (restoredListeners = TypedCollections.dynamicallyCastList((List)
restoreAttachedState(context, values[7]), FacesListener.class))) {
// if there were some listeners registered prior to this
// method being invoked, merge them with the list to be
// restored.
if (null != listeners) {
listeners.addAll(restoredListeners);
}
else {
listeners = restoredListeners;
}
}
attributesThatAreSet = (List< String >) values[8];
}
|
public static Object saveAttachedState(FacesContext context,
Object attachedObject) {
if (null == context) {
throw new NullPointerException();
}
if (null == attachedObject) {
return null;
}
Object result;
if (attachedObject instanceof List) {
List attachedList = (List) attachedObject;
List< StateHolderSaver > resultList = new ArrayList< StateHolderSaver >(attachedList.size());
Iterator listIter = attachedList.iterator();
Object cur;
while (listIter.hasNext()) {
if (null != (cur = listIter.next())) {
resultList.add(new StateHolderSaver(context, cur));
}
}
result = resultList;
}
else {
result = new StateHolderSaver(context, attachedObject);
}
return result;
}
This method is called by UIComponent subclasses that
want to save one or more attached objects. It is a convenience
method that does the work of saving attached objects that may or
may not implement the StateHolder interface. Using this
method implies the use of #restoreAttachedState to restore
the attached objects.
This method supports saving attached objects of the following
type: Objects,
null values, and Lists of these
objects. If any contained objects are not Lists
and do not implement StateHolder , they must have
zero-argument public constructors. The exact structure of the
returned object is undefined and opaque, but will be serializable.
|
public Object saveState(FacesContext context) {
if (values == null) {
values = new Object[9];
}
if (attributes != null) {
Map backing = attributes.getBackingAttributes();
if (backing != null && !backing.isEmpty()) {
values[0] = backing;
}
}
values[1] = saveBindingsState(context);
values[2] = clientId;
values[3] = id;
values[4] = rendered ? Boolean.TRUE : Boolean.FALSE;
values[5] = renderedSet ? Boolean.TRUE : Boolean.FALSE;
values[6] = rendererType;
values[7] = saveAttachedState(context, listeners);
values[8] = attributesThatAreSet;
assert(!transientFlag);
return (values);
}
|
public void setId(String id) {
// if the current ID is not null, and the passed
// argument is the same, no need to validate it
// as it has already been validated.
if (this.id == null || !(this.id.equals(id))) {
validateId(id);
this.id = id;
}
this.clientId = null; // Erase any cached value
}
|
public void setParent(UIComponent parent) {
this.parent = parent;
}
|
public void setRendered(boolean rendered) {
this.rendered = rendered;
this.renderedSet = true;
}
|
public void setRendererType(String rendererType) {
this.rendererType = rendererType;
}
|
public void setTransient(boolean transientFlag) {
this.transientFlag = transientFlag;
}
|
public void setValueBinding(String name,
ValueBinding binding) {
if (name == null) {
throw new NullPointerException();
}
if (binding != null) {
ValueExpressionValueBindingAdapter adapter =
new ValueExpressionValueBindingAdapter(binding);
setValueExpression(name, adapter);
} else {
setValueExpression(name, null);
}
} Deprecated! This - has been replaced by #setValueExpression .
|