You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/09/23 23:13:21 UTC
svn commit: r818266 - in /myfaces/core/trunk:
api/src/main/java/javax/faces/component/
impl/src/main/java/org/apache/myfaces/view/facelets/
impl/src/main/java/org/apache/myfaces/view/facelets/compiler/
impl/src/main/java/org/apache/myfaces/view/facelet...
Author: lu4242
Date: Wed Sep 23 21:13:21 2009
New Revision: 818266
URL: http://svn.apache.org/viewvc?rev=818266&view=rev
Log:
MYFACES-2337 Implement UniqueIdVendor.createUniqueId method and review all related code to UniqueIdVendor
Modified:
myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java
myfaces/core/trunk/api/src/main/java/javax/faces/component/UIData.java
myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java
myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentUtils.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILiteralTextHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UITextHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java?rev=818266&r1=818265&r2=818266&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java Wed Sep 23 21:13:21 2009
@@ -765,17 +765,31 @@
{
// Although this is an error prone side effect, we automatically create a new id
// just to be compatible to the RI
- UIViewRoot viewRoot = context.getViewRoot();
- if (viewRoot != null)
+
+ // The documentation of UniqueIdVendor says that this interface should be implemented by
+ // components that also implements NamingContainer. The only component that does not implement
+ // NamingContainer but UniqueIdVendor is UIViewRoot. Anyway we just can't be 100% sure about this
+ // fact, so it is better to scan for the closest UniqueIdVendor. If it is not found use
+ // viewRoot.createUniqueId, otherwise use UniqueIdVendor.createUniqueId(context,seed).
+ UniqueIdVendor parentUniqueIdVendor = _ComponentUtils.findParentUniqueIdVendor(this);
+ if (parentUniqueIdVendor == null)
{
- id = viewRoot.createUniqueId();
+ UIViewRoot viewRoot = context.getViewRoot();
+ if (viewRoot != null)
+ {
+ id = viewRoot.createUniqueId();
+ }
+ else
+ {
+ // The RI throws a NPE
+ throw new FacesException(
+ "Cannot create clientId. No id is assigned for component to create an id and UIViewRoot is not defined: "
+ + getPathToComponent(this));
+ }
}
else
{
- // The RI throws a NPE
- throw new FacesException(
- "Cannot create clientId. No id is assigned for component to create an id and UIViewRoot is not defined: "
- + getPathToComponent(this));
+ id = parentUniqueIdVendor.createUniqueId(context, null);
}
setId(id);
// We remember that the id was null and log a warning down below
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIData.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIData.java?rev=818266&r1=818265&r2=818266&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIData.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIData.java Wed Sep 23 21:13:21 2009
@@ -30,8 +30,10 @@
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
+import javax.faces.component.UINamingContainer.PropertyKeys;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
@@ -698,8 +700,22 @@
@Override
public String createUniqueId(FacesContext context, String seed)
{
- // TODO: IMPLEMENT HERE
- return null;
+ ExternalContext extCtx = context.getExternalContext();
+ StringBuilder bld = __getSharedStringBuilder();
+
+ Long uniqueIdCounter = (Long) getStateHelper().get(PropertyKeys.uniqueIdCounter);
+ uniqueIdCounter = (uniqueIdCounter == null) ? 0 : uniqueIdCounter;
+ getStateHelper().put(PropertyKeys.uniqueIdCounter, (uniqueIdCounter+1L));
+ // Generate an identifier for a component. The identifier will be prefixed with UNIQUE_ID_PREFIX, and will be unique within this UIViewRoot.
+ if(seed==null)
+ {
+ return extCtx.encodeNamespace(bld.append(UIViewRoot.UNIQUE_ID_PREFIX).append(uniqueIdCounter).toString());
+ }
+ // Optionally, a unique seed value can be supplied by component creators which should be included in the generated unique id.
+ else
+ {
+ return extCtx.encodeNamespace(bld.append(UIViewRoot.UNIQUE_ID_PREFIX).append(seed).toString());
+ }
}
/**
@@ -1113,6 +1129,7 @@
, first
, rows
, var
+ , uniqueIdCounter
}
@Override
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java?rev=818266&r1=818265&r2=818266&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java Wed Sep 23 21:13:21 2009
@@ -20,6 +20,8 @@
import java.util.Iterator;
+import javax.faces.component.UINamingContainer.PropertyKeys;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
@@ -47,8 +49,22 @@
@Override
public String createUniqueId(FacesContext context, String seed)
{
- // TODO: IMPLEMENT HERE
- return null;
+ ExternalContext extCtx = context.getExternalContext();
+ StringBuilder bld = __getSharedStringBuilder();
+
+ Long uniqueIdCounter = (Long) getStateHelper().get(PropertyKeys.uniqueIdCounter);
+ uniqueIdCounter = (uniqueIdCounter == null) ? 0 : uniqueIdCounter;
+ getStateHelper().put(PropertyKeys.uniqueIdCounter, (uniqueIdCounter+1L));
+ // Generate an identifier for a component. The identifier will be prefixed with UNIQUE_ID_PREFIX, and will be unique within this UIViewRoot.
+ if(seed==null)
+ {
+ return extCtx.encodeNamespace(bld.append(UIViewRoot.UNIQUE_ID_PREFIX).append(uniqueIdCounter).toString());
+ }
+ // Optionally, a unique seed value can be supplied by component creators which should be included in the generated unique id.
+ else
+ {
+ return extCtx.encodeNamespace(bld.append(UIViewRoot.UNIQUE_ID_PREFIX).append(seed).toString());
+ }
}
public boolean isSubmitted()
@@ -117,7 +133,8 @@
enum PropertyKeys
{
- prependId
+ prependId,
+ uniqueIdCounter
}
@Override
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentUtils.java?rev=818266&r1=818265&r2=818266&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentUtils.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentUtils.java Wed Sep 23 21:13:21 2009
@@ -69,6 +69,21 @@
return null;
}
+ static UniqueIdVendor findParentUniqueIdVendor(UIComponent component)
+ {
+ UIComponent parent = component.getParent();
+
+ while (parent != null)
+ {
+ if (parent instanceof UniqueIdVendor)
+ {
+ return (UniqueIdVendor) parent;
+ }
+ parent = parent.getParent();
+ }
+ return null;
+ }
+
static UIComponent getRootComponent(UIComponent component)
{
UIComponent parent;
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java?rev=818266&r1=818265&r2=818266&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java Wed Sep 23 21:13:21 2009
@@ -19,15 +19,12 @@
package org.apache.myfaces.view.facelets;
import java.io.IOException;
-import java.util.ArrayDeque;
-import java.util.Deque;
-import java.util.Map;
import javax.el.ELException;
import javax.faces.FacesException;
import javax.faces.application.Resource;
import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
+import javax.faces.component.UniqueIdVendor;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
@@ -41,6 +38,9 @@
* The methods here are only used by the current implementation and the intention
* is not expose it as public api.
*
+ * Aditionally, it also contains methods used by the current implementation for
+ * implement new features, like composite components and UniqueIdVendor support.
+ *
* @author Leonardo Uribe (latest modification by $Author$)
* @version $Revision$ $Date$
*
@@ -50,6 +50,9 @@
{
public final static String COMPOSITE_COMPONENT_STACK = "org.apache.myfaces.view.facelets.COMPOSITE_COMPONENT_STACK";
+ public final static String UNIQUEID_VENDOR_STACK = "org.apache.myfaces.view.facelets.UNIQUEID_VENDOR_STACK";
+
+
/**
* Push the passed TemplateClient onto the stack for Definition Resolution
* @param client
@@ -108,12 +111,42 @@
* This could be used by InsertChildrenHandler and InsertFacetHandler to retrieve the current
* composite component to be applied.
*
+ * @since 2.0
* @param facesContext
* @return
*/
public abstract UIComponent getCompositeComponentFromStack();
+ /**
+ * @since 2.0
+ * @param parent
+ */
public abstract void pushCompositeComponentToStack(UIComponent parent);
+ /**
+ * @since 2.0
+ */
public abstract void popCompositeComponentToStack();
+
+ /**
+ * Return the latest UniqueIdVendor created from stack. The reason why we need to keep
+ * a UniqueIdVendor stack is because we need to look the closest one in ComponentTagHandlerDelegate.
+ * Note that facelets tree is built from leafs to root, that means use UIComponent.getParent() does not
+ * always return parent components.
+ *
+ * @since 2.0
+ * @return
+ */
+ public abstract UniqueIdVendor getUniqueIdVendorFromStack();
+
+ /**
+ * @since 2.0
+ * @param parent
+ */
+ public abstract void pushUniqueIdVendorToStack(UniqueIdVendor parent);
+
+ /**
+ * @since 2.0
+ */
+ public abstract void popUniqueIdVendorToStack();
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java?rev=818266&r1=818265&r2=818266&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java Wed Sep 23 21:13:21 2009
@@ -24,9 +24,11 @@
import javax.el.ELException;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
+import javax.faces.component.UniqueIdVendor;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
+import org.apache.myfaces.view.facelets.AbstractFaceletContext;
import org.apache.myfaces.view.facelets.el.ELText;
import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
import org.apache.myfaces.view.facelets.util.FastWriter;
@@ -114,7 +116,21 @@
c = new UIInstructions(txt, applied);
// mark it owned by a facelet instance
- c.setId(ComponentSupport.getViewRoot(ctx, parent).createUniqueId());
+ //c.setId(ComponentSupport.getViewRoot(ctx, parent).createUniqueId());
+ AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
+ UniqueIdVendor uniqueIdVendor = actx.getUniqueIdVendorFromStack();
+ if (uniqueIdVendor == null)
+ {
+ uniqueIdVendor = ComponentSupport.getViewRoot(ctx, parent);
+ }
+ if (uniqueIdVendor != null)
+ {
+ // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
+ // and call createUniqueId(). Also, note that UIViewRoot.createUniqueId() javadoc
+ // says we could send as seed the facelet generated id.
+ String uid = uniqueIdVendor.createUniqueId(ctx.getFacesContext(), id);
+ c.setId(uid);
+ }
c.getAttributes().put(ComponentSupport.MARK_CREATED, id);
}
// finish cleaning up orphaned children
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILiteralTextHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILiteralTextHandler.java?rev=818266&r1=818265&r2=818266&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILiteralTextHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILiteralTextHandler.java Wed Sep 23 21:13:21 2009
@@ -23,9 +23,11 @@
import javax.el.ELException;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
+import javax.faces.component.UniqueIdVendor;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
+import org.apache.myfaces.view.facelets.AbstractFaceletContext;
import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
final class UILiteralTextHandler extends AbstractUIHandler
@@ -44,7 +46,20 @@
if (parent != null)
{
UIComponent c = new UILiteralText(this.txtString);
- c.setId(ComponentSupport.getViewRoot(ctx, parent).createUniqueId());
+ //c.setId(ComponentSupport.getViewRoot(ctx, parent).createUniqueId());
+ AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
+ UniqueIdVendor uniqueIdVendor = actx.getUniqueIdVendorFromStack();
+ if (uniqueIdVendor == null)
+ {
+ uniqueIdVendor = ComponentSupport.getViewRoot(ctx, parent);
+ }
+ if (uniqueIdVendor != null)
+ {
+ // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
+ // and call createUniqueId()
+ String uid = uniqueIdVendor.createUniqueId(ctx.getFacesContext(), null);
+ c.setId(uid);
+ }
this.addComponent(ctx, parent, c);
}
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UITextHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UITextHandler.java?rev=818266&r1=818265&r2=818266&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UITextHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UITextHandler.java Wed Sep 23 21:13:21 2009
@@ -24,9 +24,11 @@
import javax.el.ELException;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
+import javax.faces.component.UniqueIdVendor;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
+import org.apache.myfaces.view.facelets.AbstractFaceletContext;
import org.apache.myfaces.view.facelets.el.ELText;
import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
import org.apache.myfaces.view.facelets.util.FastWriter;
@@ -60,7 +62,20 @@
{
ELText nt = this.txt.apply(ctx.getExpressionFactory(), ctx);
UIComponent c = new UIText(this.alias, nt);
- c.setId(ComponentSupport.getViewRoot(ctx, parent).createUniqueId());
+ //c.setId(ComponentSupport.getViewRoot(ctx, parent).createUniqueId());
+ AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
+ UniqueIdVendor uniqueIdVendor = actx.getUniqueIdVendorFromStack();
+ if (uniqueIdVendor == null)
+ {
+ uniqueIdVendor = ComponentSupport.getViewRoot(ctx, parent);
+ }
+ if (uniqueIdVendor != null)
+ {
+ // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
+ // and call createUniqueId()
+ String uid = uniqueIdVendor.createUniqueId(ctx.getFacesContext(), null);
+ c.setId(uid);
+ }
this.addComponent(ctx, parent, c);
}
catch (Exception e)
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java?rev=818266&r1=818265&r2=818266&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java Wed Sep 23 21:13:21 2009
@@ -40,6 +40,7 @@
import javax.faces.FacesException;
import javax.faces.application.Resource;
import javax.faces.component.UIComponent;
+import javax.faces.component.UniqueIdVendor;
import javax.faces.context.FacesContext;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
@@ -104,7 +105,7 @@
_ctx = faces.getELContext();
_ids = new HashMap<String, Integer>();
_prefixes = new HashMap<Integer, Integer>();
- _clients = new ArrayList(5);
+ _clients = new ArrayList<TemplateManager>(5);
_faces = faces;
_faceletHierarchy = new ArrayList<DefaultFacelet>(1);
_faceletHierarchy.add(facelet);
@@ -446,6 +447,7 @@
}
@Override
+ @SuppressWarnings("unchecked")
public UIComponent getCompositeComponentFromStack()
{
Map<Object, Object> attributes = getFacesContext().getAttributes();
@@ -459,6 +461,7 @@
}
@Override
+ @SuppressWarnings("unchecked")
public void pushCompositeComponentToStack(UIComponent parent) {
Map<Object, Object> attributes = getFacesContext().getAttributes();
@@ -473,6 +476,7 @@
}
@Override
+ @SuppressWarnings("unchecked")
public void popCompositeComponentToStack()
{
Map<Object, Object> contextAttributes = getFacesContext().getAttributes();
@@ -482,6 +486,49 @@
{
componentStack.pop();
}
- }
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public UniqueIdVendor getUniqueIdVendorFromStack()
+ {
+ Map<Object, Object> attributes = getFacesContext().getAttributes();
+
+ Deque<UniqueIdVendor> componentStack = (Deque<UniqueIdVendor>) attributes.get(AbstractFaceletContext.UNIQUEID_VENDOR_STACK);
+ if(componentStack != null && !componentStack.isEmpty())
+ {
+ return componentStack.peek();
+ }
+ return null;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void popUniqueIdVendorToStack()
+ {
+ Map<Object, Object> contextAttributes = getFacesContext().getAttributes();
+
+ Deque<UniqueIdVendor> uniqueIdVendorStack = (Deque<UniqueIdVendor>) contextAttributes.get(AbstractFaceletContext.UNIQUEID_VENDOR_STACK);
+ if(uniqueIdVendorStack != null && !uniqueIdVendorStack.isEmpty())
+ {
+ uniqueIdVendorStack.pop();
+ }
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void pushUniqueIdVendorToStack(UniqueIdVendor parent)
+ {
+ Map<Object, Object> attributes = getFacesContext().getAttributes();
+
+ Deque<UniqueIdVendor> componentStack = (Deque<UniqueIdVendor>) attributes.get(AbstractFaceletContext.UNIQUEID_VENDOR_STACK);
+ if(componentStack == null)
+ {
+ componentStack = new ArrayDeque<UniqueIdVendor>();
+ attributes.put(AbstractFaceletContext.UNIQUEID_VENDOR_STACK, componentStack);
+ }
+
+ componentStack.push(parent);
+ }
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java?rev=818266&r1=818265&r2=818266&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java Wed Sep 23 21:13:21 2009
@@ -185,18 +185,21 @@
// Set an id to the created facet component, to prevent id generation and make
// partial state saving work without problem.
- UniqueIdVendor root = ComponentSupport.getClosestUniqueIdVendor(faceletContext.getFacesContext(), compositeFacetPanel);
- if (root != null)
+ AbstractFaceletContext actx = (AbstractFaceletContext) faceletContext;
+ UniqueIdVendor uniqueIdVendor = actx.getUniqueIdVendorFromStack();
+ if (uniqueIdVendor == null)
+ {
+ uniqueIdVendor = ComponentSupport.getViewRoot(faceletContext, compositeComponentBase);
+ }
+ if (uniqueIdVendor != null)
{
- String uid = (root instanceof UIViewRoot) ?
- ((UIViewRoot)root).createUniqueId() :
- root.createUniqueId(faceletContext.getFacesContext(),
- faceletContext.generateUniqueId(this.getTagId()));
+ // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
+ // and call createUniqueId()
+ String uid = uniqueIdVendor.createUniqueId(faceletContext.getFacesContext(),null);
compositeFacetPanel.setId(uid);
}
VariableMapper orig = faceletContext.getVariableMapper();
- AbstractFaceletContext actx = (AbstractFaceletContext) faceletContext;
try
{
faceletContext.setVariableMapper(new VariableMapperWrapper(orig));
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java?rev=818266&r1=818265&r2=818266&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java Wed Sep 23 21:13:21 2009
@@ -27,7 +27,6 @@
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
-import javax.faces.component.UniqueIdVendor;
import javax.faces.context.FacesContext;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.TagAttribute;
@@ -204,43 +203,6 @@
return ctx.getFacesContext().getViewRoot();
}
- public static UniqueIdVendor getClosestUniqueIdVendor(FacesContext facesContext, UIComponent parent)
- {
- UIComponent c = parent;
- do
- {
- if (c instanceof UniqueIdVendor)
- {
- return (UniqueIdVendor) c;
- }
- else
- {
- c = c.getParent();
- }
- } while (c != null);
-
- return facesContext.getViewRoot();
- }
-
- /*
- public static UniqueIdVendor getClosestUniqueIdVendor(UIComponent parent)
- {
- UIComponent c = parent;
- do
- {
- if (c instanceof UniqueIdVendor)
- {
- return (UniqueIdVendor) c;
- }
- else
- {
- c = c.getParent();
- }
- } while (c != null);
-
- return null;
- }*/
-
/**
* Marks all direct children and Facets with an attribute for deletion.
*
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java?rev=818266&r1=818265&r2=818266&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java Wed Sep 23 21:13:21 2009
@@ -40,6 +40,7 @@
import javax.faces.view.facelets.TagException;
import javax.faces.view.facelets.TagHandlerDelegate;
+import org.apache.myfaces.view.facelets.AbstractFaceletContext;
import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
import org.apache.myfaces.view.facelets.tag.MetaRulesetImpl;
import org.apache.myfaces.view.facelets.tag.jsf.core.FacetHandler;
@@ -116,6 +117,9 @@
// our id
String id = ctx.generateUniqueId(_delegate.getTagId());
+ // Cast to use UniqueIdVendor stuff
+ AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
+
// grab our component
UIComponent c = ComponentSupport.findChildByTagId(parent, id);
boolean componentFound = false;
@@ -147,7 +151,7 @@
c.getAttributes().put(UIComponent.VIEW_LOCATION_KEY,
_delegate.getTag().getLocation());
}
-
+
// assign our unique id
if (this._id != null)
{
@@ -155,12 +159,16 @@
}
else
{
- UniqueIdVendor root = ComponentSupport.getClosestUniqueIdVendor(facesContext, parent);
- if (root != null)
+ UniqueIdVendor uniqueIdVendor = actx.getUniqueIdVendorFromStack();
+ if (uniqueIdVendor == null)
+ {
+ uniqueIdVendor = facesContext.getViewRoot();
+ }
+ if (uniqueIdVendor != null)
{
- String uid = (root instanceof UIViewRoot) ?
- ((UIViewRoot)root).createUniqueId() :
- root.createUniqueId(facesContext, id);
+ // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
+ // and call createUniqueId()
+ String uid = uniqueIdVendor.createUniqueId(facesContext, id);
c.setId(uid);
}
}
@@ -175,6 +183,10 @@
}
c.pushComponentToEL(facesContext, c);
+ if (c instanceof UniqueIdVendor)
+ {
+ actx.pushUniqueIdVendorToStack((UniqueIdVendor)c);
+ }
// first allow c to get populated
_delegate.applyNextHandler(ctx, c);
@@ -202,7 +214,12 @@
{
parent.getFacets().put(facetName, c);
}
-
+
+ if (c instanceof UniqueIdVendor)
+ {
+ actx.popUniqueIdVendorToStack();
+ }
+
c.popComponentFromEL(facesContext);
if (facesContext.getAttributes().containsKey(