You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ar...@apache.org on 2010/08/11 02:06:52 UTC
svn commit: r984270 [2/2] - in
/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4: ./
trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/
trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/core/layo...
Modified: myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java?rev=984270&r1=984269&r2=984270&view=diff
==============================================================================
--- myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java (original)
+++ myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java Wed Aug 11 00:06:51 2010
@@ -251,7 +251,7 @@ abstract public class UIXComponent exten
{
ComponentProcessingContext processingContext = new ComponentProcessingContext();
processingContext.__setIsRendering();
-
+
return processFlattenedChildren(context,
processingContext,
childProcessor,
@@ -327,6 +327,81 @@ abstract public class UIXComponent exten
}
/**
+ * Hook for subclasses to override the manner in which the component's children are visited. The default
+ * implementation visits all of the children and facets of the Component.
+ * <code>setupChildrenVisitingContext</code> will have been called before this method is
+ * invoked and <code>tearDownChildrenVisitingContext</code> will be called after.
+ * respectively. If the purpose of this visit was to encode the component and the
+ * component uses a CoreRenderer, the CoreRenderer's
+ * <code>setupChildrenEncodingContext</code> and <code>tearDownChildrenEncodingContext</code>
+ * will be called before and after this method is invoked, respectively.
+ * @param visitContext the <code>VisitContext</code> for this visit
+ * @param callback the <code>VisitCallback</code> instance
+ * @return <code>true</code> if the visit is complete.
+ * @see #setupChildrenVisitingContext
+ * @see #tearDownChildrenVisitingContext
+ * @see org.apache.myfaces.trinidad.render.CoreRenderer#setupChildrenEncodingContext
+ * @see org.apache.myfaces.trinidad.render.CoreRenderer#tearDownChildrenEncodingContext
+ */
+ protected boolean visitChildren(
+ VisitContext visitContext,
+ VisitCallback callback)
+ {
+ // See if this is during encoding, if so, allow the renderer to control the visitation of
+ // the children so that any special encoding context may be applied around the visitation
+ // of each child.
+ if (_isEncodingVisit(visitContext))
+ {
+ Renderer renderer = getRenderer(visitContext.getFacesContext());
+ if (renderer instanceof CoreRenderer)
+ {
+ CoreRenderer coreRenderer = (CoreRenderer)renderer;
+ return coreRenderer.visitChildrenForEncoding(this, visitContext, callback);
+ }
+ }
+
+ // visit all of the children of the component
+ return _visitAllChildren(this, visitContext, callback);
+ }
+
+ /**
+ * Default implementation of visiting children that visits all children without iterating
+ * @param visitContext the <code>VisitContext</code> for this visit
+ * @param callback the <code>VisitCallback</code> instance
+ * @return <code>true</code> if the visit is complete.
+ */
+ private static boolean _visitAllChildren(
+ UIComponent component,
+ VisitContext visitContext,
+ VisitCallback callback)
+ {
+ // visit the children of the component
+ Iterator<UIComponent> kids = component.getFacetsAndChildren();
+
+ while (kids.hasNext())
+ {
+ // If any kid visit returns true, we are done.
+ UIComponent kid = kids.next();
+ if (kid instanceof UIXComponent)
+ {
+ if (((UIXComponent)kid).visitTree(visitContext, callback))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (visitTree(visitContext, kid, callback))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
* <p>Perform a tree visit starting at the specified node in the tree.</p>
*
* <p>UIXComponent.visitTree() implementations do not invoke the
@@ -350,7 +425,7 @@ abstract public class UIXComponent exten
* @see VisitContext#invokeVisitCallback VisitContext.invokeVisitCallback()
*/
public static boolean visitTree(
- VisitContext visitContext,
+ VisitContext visitContext,
UIComponent component,
VisitCallback callback)
{
@@ -374,106 +449,113 @@ abstract public class UIXComponent exten
uixComponent = null;
}
- // invoke the callback for this component
- VisitResult result = visitContext.invokeVisitCallback(component, callback);
-
- if (result == VisitResult.COMPLETE)
- return true;
- else if (result == VisitResult.ACCEPT)
- {
- // now visit the children
- FacesContext context = visitContext.getFacesContext();
- PhaseId phaseId = visitContext.getPhaseId();
- RenderingContext rc = (PhaseId.RENDER_RESPONSE == phaseId)
- ? RenderingContext.getCurrentInstance()
- : null;
-
- if (uixComponent != null)
+ FacesContext facesContext = visitContext.getFacesContext();
+ RenderingContext rc = null;
+ if (uixComponent != null)
+ {
+ // We only need the rendering context if we are visiting a UIXComponent
+ rc = (uixComponent != null && _isEncodingVisit(visitContext))
+ ? RenderingContext.getCurrentInstance()
+ : null;
+
+ // UIXComponents are allowed to set up their context differently for encoding
+ // than normal processing, so behave differently if this is the RenderResponse
+ // phase
+ if (rc != null)
{
- // assume that all UIXComponent NamingContainers always act as NamingContainers,
- // (unlike <h:form>) and this it is OK to put the optimization where we
- // don't visit the children if we know that we don't have any ids in this
- // subtree to visit
- if (uixComponent instanceof NamingContainer)
- {
- if (visitContext.getSubtreeIdsToVisit(uixComponent).isEmpty())
- return false;
- }
-
- // UIXComponents are allowed to set up their context differently for encoding
- // than normal processing, so behave differently if this is the RenderResponse
- // phase
- if (PhaseId.RENDER_RESPONSE == phaseId)
- {
- uixComponent.setUpEncodingContext(context, rc);
- }
- else
- {
- uixComponent.setupVisitingContext(context);
- }
+ uixComponent.setUpEncodingContext(facesContext, rc);
}
else
{
- // we only optimize walking into non-UIXComponent NamingContainers
- // if they are UINamingConainer (which is used by <f:subview>
- if (UINamingContainer.class == component.getClass())
- {
- if (visitContext.getSubtreeIdsToVisit(component).isEmpty())
- return false;
- }
+ uixComponent.setupVisitingContext(facesContext);
}
+ }
+ try
+ {
+ // invoke the callback for this component
+ VisitResult result = visitContext.invokeVisitCallback(component, callback);
- // visit the children of the component
- try
+ if (result == VisitResult.COMPLETE)
+ return true;
+ else if (result == VisitResult.ACCEPT)
{
- Iterator<UIComponent> kids = component.getFacetsAndChildren();
-
- while(kids.hasNext())
+ // now visit the children
+ if (uixComponent != null)
{
- boolean done;
-
- UIComponent currChild = kids.next();
-
- if (currChild instanceof UIXComponent)
+ // assume that all UIXComponent NamingContainers always act as NamingContainers,
+ // (unlike <h:form>) and this it is OK to put the optimization where we
+ // don't visit the children if we know that we don't have any ids in this
+ // subtree to visit
+ if (uixComponent instanceof NamingContainer)
{
- UIXComponent uixChild = (UIXComponent)currChild;
-
- // delegate to UIXComponent's visitTree implementation to allow
- // subclassses to modify the behavior
- done = uixChild.visitTree(visitContext, callback);
+ if (visitContext.getSubtreeIdsToVisit(uixComponent).isEmpty())
+ return false;
}
- else
- {
- // use generic visit implementation
- done = visitTree(visitContext, currChild, callback);
- }
-
- // If any kid visit returns true, we are done.
- if (done)
+ }
+ else
+ {
+ // we only optimize walking into non-UIXComponent NamingContainers
+ // if they are UINamingConainer (which is used by <f:subview>
+ if (UINamingContainer.class == component.getClass())
{
- return true;
+ if (visitContext.getSubtreeIdsToVisit(component).isEmpty())
+ return false;
}
}
- }
- finally
- {
- // tear down the context we set up in order to visit our children
+
if (uixComponent != null)
{
- if (PhaseId.RENDER_RESPONSE == phaseId)
+ // setup any context needed for visiting the children of the component as opposed
+ // to the component itself
+ if (rc != null)
{
- uixComponent.tearDownEncodingContext(context, rc);
+ uixComponent.setupChildrenEncodingContext(facesContext, rc);
}
else
{
- uixComponent.tearDownVisitingContext(context);
+ uixComponent.setupChildrenVisitingContext(facesContext);
+ }
+
+ try
+ {
+ return uixComponent.visitChildren(visitContext, callback);
+ }
+ finally
+ {
+ // teardown any context initialized above
+ if (rc != null)
+ {
+ uixComponent.tearDownChildrenEncodingContext(facesContext, rc);
+ }
+ else
+ {
+ uixComponent.tearDownChildrenVisitingContext(facesContext);
+ }
}
}
+ else
+ {
+ return _visitAllChildren(component, visitContext, callback);
+ }
+ }
+ else
+ {
+ assert(result == VisitResult.REJECT);
}
}
- else
+ finally
{
- assert(result == VisitResult.REJECT);
+ if (uixComponent != null)
+ {
+ if (rc != null)
+ {
+ uixComponent.tearDownEncodingContext(facesContext, rc);
+ }
+ else
+ {
+ uixComponent.tearDownVisitingContext(facesContext);
+ }
+ }
}
// if we got this far, we're not done
@@ -481,6 +563,17 @@ abstract public class UIXComponent exten
}
/**
+ * Returns <code>true</code> if the components are being visited
+ * for the purpose of encoding.
+ */
+ private static boolean _isEncodingVisit(
+ VisitContext visitContext)
+ {
+ return (visitContext.getHints().contains(VisitHint.EXECUTE_LIFECYCLE) &&
+ visitContext.getPhaseId() == PhaseId.RENDER_RESPONSE);
+ }
+
+ /**
* Add a component as a partial target to the current request. This code handles the
* delegation to {@link #setPartialTarget(FacesContext, PartialPageContext)}
* for UIXComponents or assumes for {@link UIComponent} that components with a renderer
@@ -655,6 +748,23 @@ abstract public class UIXComponent exten
}
/**
+ * <p>Sets up the context necessary to visit or invoke the children of a component for all phases.
+ * </p>
+ * <p>The default implementation does nothing.</p>
+ * <p>If a subclass overrides this method, it should override
+ * <code>tearDownChildrenVisitingContext</code> as well.</p>
+ * <p>It is guaranteed that if <code>setupChildrenVisitingContext</code> completes
+ * <code>tearDownChildrenVisitingContext</code> will be called for this component</p>
+ * @param context FacesContext
+ * @see #visitChildren
+ * @see #tearDownChildrenVisitingContext
+ */
+ protected void setupChildrenVisitingContext(@SuppressWarnings("unused") FacesContext context)
+ {
+ // do nothing
+ }
+
+ /**
* <p>Tears down context created in order to visit or invoke the component
* for all phases.</p>
* <p>The default implementation does nothing.</p>
@@ -672,6 +782,23 @@ abstract public class UIXComponent exten
}
/**
+ * <p>Tears down context created in order to visit or invoke the children of a component
+ * for all phases.</p>
+ * <p>The default implementation does nothing.</p>
+ * <p>A subclass should only override this method if it overrode
+ * <code>setupChildrenVisitingContext</code> as well</p>
+ * <p>It is guaranteed that <code>tearDownChildrenVisitingContext</code> will be called only after
+ * <code>setupChildrenVisitingContext</code> has been called for this component</p>
+ * @param context FacesContext
+ * @see #setupChildrenVisitingContext
+ * @see #visitChildren
+ */
+ protected void tearDownChildrenVisitingContext(@SuppressWarnings("unused") FacesContext context)
+ {
+ // do nothing
+ }
+
+ /**
* <p>Sets up the context necessary to encode the component.</p>
* <p>The default implementation delegates to
* <code>CoreRenderer.setupEncodingContext</code> and then calls
@@ -700,6 +827,28 @@ abstract public class UIXComponent exten
}
/**
+ * Sets the context necessary to encode the children of a component.
+ * @param context The FacesContext
+ * @param rc RenderingContext to use for encoding
+ * @see #setupChildrenVisitingContext
+ * @see #tearDownChildrenEncodingContext
+ * @see org.apache.myfaces.trinidad.render.CoreRenderer#setupChildrenEncodingContext
+ */
+ public void setupChildrenEncodingContext(FacesContext context, RenderingContext rc)
+ {
+ setupChildrenVisitingContext(context);
+
+ Renderer renderer = getRenderer(context);
+
+ if (renderer instanceof CoreRenderer)
+ {
+ CoreRenderer coreRenderer = (CoreRenderer)renderer;
+
+ coreRenderer.setupChildrenEncodingContext(context, rc, this);
+ }
+ }
+
+ /**
* <p>Tears down the context created in order to encode the component</p>
* <p>The default implementation delegates to
* <code>CoreRenderer.tearDownEncodingContext</code> and then calls
@@ -735,6 +884,35 @@ abstract public class UIXComponent exten
}
/**
+ * Tears down the context necessary to encode the children of a component.
+ * @param context The FacesContext
+ * @param rc RenderingContext to use for encoding
+ * @see #setupChildrenVisitingContext
+ * @see #tearDownChildrenEncodingContext
+ * @see org.apache.myfaces.trinidad.render.CoreRenderer#setupChildrenEncodingContext
+ */
+ public void tearDownChildrenEncodingContext(
+ FacesContext context,
+ RenderingContext rc)
+ {
+ Renderer renderer = getRenderer(context);
+
+ try
+ {
+ if (renderer instanceof CoreRenderer)
+ {
+ CoreRenderer coreRenderer = (CoreRenderer)renderer;
+
+ coreRenderer.tearDownChildrenEncodingContext(context, rc, this);
+ }
+ }
+ finally
+ {
+ tearDownChildrenVisitingContext(context);
+ }
+ }
+
+ /**
* Returns the FacesBean used for storing the component's state.
*/
abstract public FacesBean getFacesBean();
Modified: myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java?rev=984270&r1=984269&r2=984270&view=diff
==============================================================================
--- myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java (original)
+++ myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java Wed Aug 11 00:06:51 2010
@@ -261,8 +261,6 @@ abstract public class UIXComponentBase e
}
}
-
-
/**
*/
@Override
@@ -282,7 +280,6 @@ abstract public class UIXComponentBase e
return getFacesBean().getValueBinding(key);
}
-
@Override
public void setValueBinding(String name, ValueBinding binding)
{
@@ -293,7 +290,6 @@ abstract public class UIXComponentBase e
getFacesBean().setValueBinding(key, binding);
}
-
@Override
public Map<String, Object> getAttributes()
{
@@ -388,19 +384,15 @@ abstract public class UIXComponentBase e
setProperty(ID_KEY, id);
}
-
-
@Override
abstract public String getFamily();
-
@Override
public UIComponent getParent()
{
return _parent;
}
-
/**
* <p>Set the parent <code>UIComponent</code> of this
* <code>UIComponent</code>.</p>
@@ -414,14 +406,12 @@ abstract public class UIXComponentBase e
_parent = parent;
}
-
@Override
public boolean isRendered()
{
return getBooleanProperty(RENDERED_KEY, true);
}
-
@Override
public void setRendered(boolean rendered)
{
@@ -470,7 +460,6 @@ abstract public class UIXComponentBase e
setProperty(RENDERER_TYPE_KEY, rendererType);
}
-
@Override
public boolean getRendersChildren()
{
@@ -481,13 +470,8 @@ abstract public class UIXComponentBase e
return renderer.getRendersChildren();
}
-
-
-
// ------------------------------------------------ Tree Management Methods
-
-
@Override
public UIComponent findComponent(String id)
{
@@ -558,8 +542,6 @@ abstract public class UIXComponentBase e
}
}
-
-
/**
* <p>Create (if necessary) and return a List of the children associated
* with this component.</p>
@@ -581,7 +563,6 @@ abstract public class UIXComponentBase e
return getChildren().size();
}
-
/**
* <p>Create (if necessary) and return a Map of the facets associated
* with this component.</p>
@@ -596,12 +577,12 @@ abstract public class UIXComponentBase e
return _facets;
}
-
@Override
public UIComponent getFacet(String facetName)
{
if (facetName == null)
throw new NullPointerException();
+
if (_facets == null)
return null;
return getFacets().get(facetName);
@@ -638,7 +619,7 @@ abstract public class UIXComponentBase e
if (_children == null)
return _facets.values().iterator();
}
-
+
return new CompositeIterator<UIComponent>(_children.iterator(), _facets.values().iterator());
}
@@ -695,7 +676,6 @@ abstract public class UIXComponentBase e
// ------------------------------------------- Lifecycle Processing Methods
-
@Override
public void decode(FacesContext context)
{
@@ -851,9 +831,9 @@ abstract public class UIXComponentBase e
if (_LOG.isFiner())
_LOG.finer("processSaveState() on " + this);
-
+
Object state = null;
-
+
try
{
if (((_children == null) || _children.isEmpty()) &&
@@ -867,17 +847,17 @@ abstract public class UIXComponentBase e
treeState.saveState(context, this);
if (treeState.isEmpty())
state = null;
-
+
state = treeState;
}
}
catch (RuntimeException e)
{
_LOG.warning(_LOG.getMessage("COMPONENT_CHILDREN_SAVED_STATE_FAILED", this));
-
+
throw e;
}
-
+
// if component state serialization checking is on, attempt to Serialize the
// component state immediately in order to determine which component's state
// failed state saving. Note that since our parent will attempt this same
@@ -888,7 +868,7 @@ abstract public class UIXComponentBase e
{
try
{
- new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(state);
+ new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(state);
}
catch (IOException e)
{
@@ -939,12 +919,13 @@ abstract public class UIXComponentBase e
return getFacesBean().saveState(context);
}
- public void restoreState(FacesContext context, Object stateObj)
+ public void restoreState(
+ FacesContext facesContext,
+ Object stateObj)
{
- getFacesBean().restoreState(context, stateObj);
+ getFacesBean().restoreState(facesContext, stateObj);
}
-
@Override
public String toString()
{
@@ -968,7 +949,6 @@ abstract public class UIXComponentBase e
return FacesContext.getCurrentInstance();
}
-
/**
* Delegates to LifecycleRenderer, if present,
* otherwise calls decodeChildrenImpl.
@@ -1003,7 +983,6 @@ abstract public class UIXComponentBase e
}
}
-
/**
* Delegates to LifecycleRenderer, if present,
* otherwise calls validateChildrenImpl.
@@ -1039,7 +1018,6 @@ abstract public class UIXComponentBase e
}
}
-
/**
* Delegates to LifecycleRenderer, if present,
* otherwise calls upateChildrenImpl.
@@ -1225,7 +1203,6 @@ abstract public class UIXComponentBase e
return n.intValue();
}
-
/**
* Return the number of facets. This is more efficient than
* calling getFacets().size();
@@ -1239,7 +1216,6 @@ abstract public class UIXComponentBase e
return _facets.size();
}
-
/**
* Broadcast an event to a MethodBinding.
* This can be used to support MethodBindings such as the "actionListener"
@@ -1315,8 +1291,12 @@ abstract public class UIXComponentBase e
/**
* Convenience method to call <code>invokeOnComponent</code> on all of the
- * children of a component. This is useful when a component sometimes optimizes
- * away calling <code>invokeOnComponent</code> on its children
+ * children of a component, surrounding the invocation with calls to
+ * <code>setup/tearDownChildrenVisitingContext</code>.
+ * This is useful when a component sometimes optimizes
+ * away calling <code>invokeOnComponent</code> on its children.
+ * @see UIXComponent#setupChildrenVisitingContext
+ * @see UIXComponent#tearDownChildrenVisitingContext
*/
protected final boolean invokeOnChildrenComponents(
FacesContext context,
@@ -1324,15 +1304,24 @@ abstract public class UIXComponentBase e
ContextCallback callback)
throws FacesException
{
- Iterator<UIComponent> children = getFacetsAndChildren();
-
+ setupChildrenVisitingContext(context);
+
boolean found = false;
-
- while (children.hasNext() && !found)
+
+ try
+ {
+ Iterator<UIComponent> children = getFacetsAndChildren();
+
+ while (children.hasNext() && !found)
+ {
+ found = children.next().invokeOnComponent(context, clientId, callback);
+ }
+ }
+ finally
{
- found = children.next().invokeOnComponent(context, clientId, callback);
+ tearDownChildrenVisitingContext(context);
}
-
+
return found;
}
@@ -1352,46 +1341,47 @@ abstract public class UIXComponentBase e
throws FacesException
{
assert this instanceof NamingContainer : "Only use invokeOnNamingContainerComponent on NamingContainers";
-
- String thisClientId = getClientId(context);
- if (clientId.equals(thisClientId))
- {
- // this is the component we want, so invoke the callback
- callback.invokeContextCallback(context, this);
- return true;
- }
- else
+ boolean invokedComponent;
+
+ setupVisitingContext(context);
+
+ try
{
- // if this is a NamingContainer, only traverse into it if the clientId we are looking for
- // is inside of it
- if ((!clientId.startsWith(thisClientId) ||
- (clientId.charAt(thisClientId.length()) != NamingContainer.SEPARATOR_CHAR)))
- {
- return false;
- }
+ String thisClientId = getClientId(context);
- boolean invokedComponent = false;
-
- // set up the context for visiting the children
- setupVisitingContext(context);
-
- try
+ if (clientId.equals(thisClientId))
{
- // iterate through children. We inline this code instead of calling super in order
- // to avoid making an extra call to getClientId().
- invokedComponent = invokeOnChildrenComponents(context, clientId, callback);
+ // this is the component we want, so invoke the callback
+ callback.invokeContextCallback(context, this);
+ return true;
}
- finally
+ else
{
- // teardown the context now that we have visited the children
- tearDownVisitingContext(context);
+ // if this is a NamingContainer, only traverse into it if the clientId we are looking for
+ // is inside of it
+ if ((!clientId.startsWith(thisClientId) ||
+ (clientId.charAt(thisClientId.length()) != NamingContainer.SEPARATOR_CHAR)))
+ {
+ invokedComponent = false;
+ }
+ else
+ {
+ // iterate through children.
+ // We inline this code instead of calling super in order
+ // to avoid making an extra call to getClientId().
+ invokedComponent = invokeOnChildrenComponents(context, clientId, callback);
+ }
}
-
- return invokedComponent;
}
+ finally
+ {
+ // teardown the context now that we have visited the children
+ tearDownVisitingContext(context);
+ }
+
+ return invokedComponent;
}
-
/**
* Override to calls the hooks for setting up and tearing down the
@@ -1405,34 +1395,32 @@ abstract public class UIXComponentBase e
String clientId,
ContextCallback callback)
throws FacesException
- {
- String thisClientId = getClientId(context);
+ {
+ boolean invokedComponent;
- if (clientId.equals(thisClientId))
- {
- callback.invokeContextCallback(context, this);
- return true;
- }
- else
+ // set up the context for visiting the children
+ setupVisitingContext(context);
+
+ try
{
- boolean invokedComponent = false;
-
- // set up the context for visiting the children
- setupVisitingContext(context);
-
- try
+ String thisClientId = getClientId(context);
+
+ if (clientId.equals(thisClientId))
{
- // iterate through children. We inline this code instead of calling super in order
- // to avoid making an extra call to getClientId().
- invokedComponent = invokeOnChildrenComponents(context, clientId, callback);
+ callback.invokeContextCallback(context, this);
+ return true;
}
- finally
+ else
{
- // teardown the context now that we have visited the children
- tearDownVisitingContext(context);
+ // iterate through children. We inline this code instead of calling super in order
+ // to avoid making an extra call to getClientId().
+ return invokeOnChildrenComponents(context, clientId, callback);
}
-
- return invokedComponent;
+ }
+ finally
+ {
+ // teardown the context now that we have visited the children
+ tearDownVisitingContext(context);
}
}
@@ -1516,7 +1504,6 @@ abstract public class UIXComponentBase e
}
}
-
static private UIComponent _findInsideOf(
UIComponent from,
String id)
Modified: myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXHierarchy.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXHierarchy.java?rev=984270&r1=984269&r2=984270&view=diff
==============================================================================
--- myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXHierarchy.java (original)
+++ myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXHierarchy.java Wed Aug 11 00:06:51 2010
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,11 +19,12 @@
package org.apache.myfaces.trinidad.component;
import java.util.Collections;
-
import java.util.List;
import javax.faces.component.UIComponent;
+import org.apache.myfaces.trinidad.component.visit.VisitCallback;
+import org.apache.myfaces.trinidad.component.visit.VisitContext;
import org.apache.myfaces.trinidad.model.CollectionModel;
import org.apache.myfaces.trinidad.model.LocalRowKeyIndex;
import org.apache.myfaces.trinidad.model.ModelUtils;
@@ -37,7 +38,7 @@ import org.apache.myfaces.trinidad.model
*
* @version $Name: $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/component/UIXHierarchy.java#0 $) $Date: 10-nov-2005.19:09:52 $
*/
-abstract public class UIXHierarchy extends UIXCollection implements CollectionComponent, LocalRowKeyIndex,
+abstract public class UIXHierarchy extends UIXCollection implements CollectionComponent, LocalRowKeyIndex,
TreeLocalRowKeyIndex
{
/**
@@ -58,7 +59,7 @@ abstract public class UIXHierarchy exten
public CollectionModel createCollectionModel(CollectionModel current, Object value)
{
TreeModel model = ModelUtils.toTreeModel(value);
- model.setRowKey(null);
+ model.setRowKey(null);
return model;
}
@@ -80,8 +81,8 @@ abstract public class UIXHierarchy exten
public int getRows()
{
return 0;
- }
-
+ }
+
/**
* Treats the current element as a parent element and steps into the children.
* A new path is constructed by appending the null value to the old path.
@@ -128,7 +129,7 @@ abstract public class UIXHierarchy exten
*/
public boolean isContainerEmpty()
{
-
+
return getTreeModel().isContainerEmpty();
}
@@ -169,7 +170,7 @@ abstract public class UIXHierarchy exten
{
return getTreeModel().getContainerRowKey(childKey);
}
-
+
/**
* Gets the all the rowKeys of the ancestors of the given child row.
* @see TreeModel#getAllAncestorContainerRowKeys(Object)
@@ -184,8 +185,8 @@ abstract public class UIXHierarchy exten
//
/**
- * Indicates whether data for a child model (children of the current node) is
- * locally available.
+ * Indicates whether data for a child model (children of the current node) is
+ * locally available.
* @see TreeModel#isChildCollectionLocallyAvailable()
* @return true if child data is locally available
*/
@@ -196,7 +197,7 @@ abstract public class UIXHierarchy exten
/**
* Indicates whether child data for the node with the given index is
- * locally available.
+ * locally available.
* @see TreeModel#isChildCollectionLocallyAvailable(int)
* @param index row index to check
* @return true if child data is available, false otherwise
@@ -208,7 +209,7 @@ abstract public class UIXHierarchy exten
/**
* Indicates whether child data for the node with the given row key is
- * locally available.
+ * locally available.
* @see TreeModel#isChildCollectionLocallyAvailable(Object)
* @param rowKey row key to check
* @return true if child data is available, false otherwise
@@ -221,7 +222,7 @@ abstract public class UIXHierarchy exten
/**
* Check if a range of rows is locally available starting from a row index. The range
* can include child nodes in any expanded nodes within the range.
- * @param startIndex staring index for the range
+ * @param startIndex staring index for the range
* @param rowCount number of rows in the range
* @param disclosedRowKeys set of expanded nodes which may fall within the range to check for
* availability
@@ -237,7 +238,7 @@ abstract public class UIXHierarchy exten
/**
* Check if a range of rows is locally available starting from a row key. The range
* can include child nodes in any expanded nodes within the range.
- * @param startRowKey staring row key for the range
+ * @param startRowKey staring row key for the range
* @param rowCount number of rows in the range
* @param disclosedRowKeys set of expanded nodes which may fall within the range to check for
* availability
@@ -273,8 +274,8 @@ abstract public class UIXHierarchy exten
{
TreeModel model = (TreeModel) getCollectionModel();
return model;
- }
-
+ }
+
@Override
protected List<UIComponent> getStamps()
{
@@ -283,7 +284,94 @@ abstract public class UIXHierarchy exten
return Collections.singletonList(nodeStamp);
else
return Collections.emptyList();
- }
+ }
abstract public Object getFocusRowKey();
+
+ protected final boolean visitLevel(
+ VisitContext visitContext,
+ VisitCallback callback,
+ List<UIComponent> stamps)
+ {
+ if (getRowCount() != 0)
+ {
+ if (!stamps.isEmpty())
+ {
+ int oldRow = getRowIndex();
+ int first = getFirst();
+ int last = TableUtils.getLast(this, first);
+
+ try
+ {
+ for (int i = first; i <= last; i++)
+ {
+ setRowIndex(i);
+
+ for (UIComponent currStamp : stamps)
+ {
+ // visit the stamps. If we have visited all of the visit targets then return early
+ if (UIXComponent.visitTree(visitContext, currStamp, callback))
+ return true;
+ }
+ }
+ }
+ finally
+ {
+ setRowIndex(oldRow);
+ }
+ }
+ }
+
+ return false;
+ }
+
+ protected final boolean visitHierarchy(
+ VisitContext visitContext,
+ VisitCallback callback,
+ List<UIComponent> stamps,
+ RowKeySet disclosedRowKeys)
+ {
+ int oldRow = getRowIndex();
+ int first = getFirst();
+ int last = TableUtils.getLast(this, first);
+
+ try
+ {
+ for(int i = first; i <= last; i++)
+ {
+ setRowIndex(i);
+ if (!stamps.isEmpty())
+ {
+ for (UIComponent currStamp : stamps)
+ {
+ // visit the stamps. If we have visited all of the visit targets then return early
+ if (UIXComponent.visitTree(visitContext, currStamp, callback))
+ return true;
+ }
+ }
+
+ if (isContainer() && ((disclosedRowKeys == null) || disclosedRowKeys.isContained()))
+ {
+ enterContainer();
+
+ try
+ {
+ // visit this container. If we have visited all of the visit targets then return early
+ if (visitHierarchy(visitContext, callback, stamps, disclosedRowKeys))
+ return true;
+ }
+ finally
+ {
+ exitContainer();
+ }
+ }
+ }
+ }
+ finally
+ {
+ setRowIndex(oldRow);
+ }
+
+ return false;
+ }
}
Modified: myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java?rev=984270&r1=984269&r2=984270&view=diff
==============================================================================
--- myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java (original)
+++ myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java Wed Aug 11 00:06:51 2010
@@ -129,6 +129,27 @@ public class CoreRenderer extends Render
/**
* <p>
+ * Called before rendering the current component's children in order to set
+ * up any special context.
+ * </p>
+ * <p>If <code>setupChildrenEncodingContext</code> succeeds then
+ * <code>tearDownChildrenEncodingContext</code> will be called for the same component.
+ * </p>
+ * <p>The default implementation does nothing</p>
+ * @param context FacesContext for this request
+ * @param rc RenderingContext for this encoding pass
+ * @param component Component to encode using this Renderer
+ * @see #tearDownChildrenEncodingContext
+ */
+ public void setupChildrenEncodingContext(
+ @SuppressWarnings("unused") FacesContext context,
+ @SuppressWarnings("unused") RenderingContext rc,
+ @SuppressWarnings("unused") UIComponent component)
+ {
+ }
+
+ /**
+ * <p>
* Called after rendering the current component's children in order to tear
* down any special context.
* </p>
@@ -161,6 +182,68 @@ public class CoreRenderer extends Render
tearDownEncodingContext(context, rc, (UIXComponent)component);
}
+ /**
+ * <p>
+ * Called after rendering the current component's children in order to tear
+ * down any special context.
+ * </p>
+ * <p>
+ * <code>tearDownChildrenEncodingContext</code> will be called on the component if
+ * <code>setupChildrenEncodingContext</code> succeeded.
+ * </p>
+ * <p>The default implementation does nothing</p>
+ * @param context FacesContext for this request
+ * @param rc RenderingContext for this encoding pass
+ * @param component Component to encode using this Renderer
+ * @see #setupChildrenEncodingContext
+ */
+ public void tearDownChildrenEncodingContext(
+ @SuppressWarnings("unused") FacesContext context,
+ @SuppressWarnings("unused") RenderingContext rc,
+ @SuppressWarnings("unused") UIComponent component)
+ {
+ }
+
+ /**
+ * Hook to allow the renderer to customize the visitation of the children components
+ * of a component during the visitation of a component during rendering.
+ *
+ * @param component the component which owns the children to visit
+ * @param visitContext the visitation context
+ * @param callback the visit callback
+ * @return <code>true</code> if the visit is complete.
+ * @see UIXComponent#visitChildren(VisitContext, VisitCallback)
+ */
+ public boolean visitChildrenForEncoding(
+ UIXComponent component,
+ VisitContext visitContext,
+ VisitCallback callback)
+ {
+ // visit the children of the component
+ Iterator<UIComponent> kids = component.getFacetsAndChildren();
+
+ while (kids.hasNext())
+ {
+ // If any kid visit returns true, we are done.
+ UIComponent kid = kids.next();
+ if (kid instanceof UIXComponent)
+ {
+ if (((UIXComponent)kid).visitTree(visitContext, callback))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (UIXComponent.visitTree(visitContext, kid, callback))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
//
// COERCION HELPERS
@@ -684,9 +767,9 @@ public class CoreRenderer extends Render
{
return (Agent.PLATFORM_GENERICPDA.equals(rc.getAgent().getPlatformName()));
}
-
+
/**
- * This method returns true if a user-agent's platform is NokiaS60
+ * This method returns true if a user-agent's platform is NokiaS60
* @param arc - RenderingContext of a request
* @return boolean
*/
Propchange: myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug 11 00:06:51 2010
@@ -3,4 +3,7 @@
/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component:895708
/myfaces/trinidad/branches/1.2.9.1-branch/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component:699406,699496
/myfaces/trinidad/branches/TRINIDAD-1402/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component:745675
+/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component:964963-966042
+/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_2/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component:966043-984257
+/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_3/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component:984258-984269
/myfaces/trinidad/trunk/trinidad-sandbox/sandbox-api/src/main/java-templates/org/apache/myfaces/trinidad/sandbox/component:894885,915962,962582
Propchange: myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug 11 00:06:51 2010
@@ -3,4 +3,7 @@
/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event:895708
/myfaces/trinidad/branches/1.2.9.1-branch/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event:699406,699496
/myfaces/trinidad/branches/TRINIDAD-1402/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event:745675
+/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event:964963-966042
+/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_2/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event:966043-984257
+/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_3/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event:984258-984269
/myfaces/trinidad/trunk/trinidad-sandbox/sandbox-api/src/main/java/org/apache/myfaces/trinidad/sandbox/event:894885,915962,962582