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 2011/08/14 20:06:52 UTC
svn commit: r1157584 - in
/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component:
UIComponentBase.java _ComponentUtils.java
Author: lu4242
Date: Sun Aug 14 18:06:51 2011
New Revision: 1157584
URL: http://svn.apache.org/viewvc?rev=1157584&view=rev
Log:
MYFACES-3268 UIComponentBase.findComponent does not allow use the same id for a child component.
Modified:
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponentBase.java
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentUtils.java
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponentBase.java?rev=1157584&r1=1157583&r2=1157584&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponentBase.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponentBase.java Sun Aug 14 18:06:51 2011
@@ -616,34 +616,35 @@ public abstract class UIComponentBase ex
throw new IllegalArgumentException("Intermediate identifier " + id + " in search expression " + expr
+ " identifies a UIComponent that is not a NamingContainer");
- // At this point, findBase has a NamingContainer that match with the id.
- // So we need to call findComponent over the rest of the expression without take
- // into account the base id, to allow use the same id on the inner component.
- //return findBase.findComponent(expr.substring(separator + 1));
- String innerExpr = expr.substring(separator + 1);
- if (findBase.getFacetCount() > 0)
+ if (id.equals(findBase.getId()))
{
- for (UIComponent facet : findBase.getFacets().values())
+ // At this point, findBase has a NamingContainer that match with the id.
+ // So we need to call findComponent over the rest of the expression without take
+ // into account the base id, to allow use the same id on the inner component.
+ //return findBase.findComponent(expr.substring(separator + 1));
+ String innerExpr = expr.substring(separator + 1);
+ separator = innerExpr.indexOf(separatorChar);
+ //String innerExpr1 = null;
+ //String nextId = null;
+ if (separator == -1)
+ {
+ //innerExpr1 = null;
+ //nextId= innerExpr;
+ return _ComponentUtils.innerFindComponent(findBase, innerExpr, null);
+ }
+ else
{
- UIComponent find = facet.findComponent(innerExpr);
- if (find != null)
- {
- return find;
- }
+ //innerExpr1 = innerExpr.substring(separator+1);
+ //nextId = innerExpr.substring(0,separator);
+ return _ComponentUtils.innerFindComponent(findBase, innerExpr.substring(0,separator), innerExpr);
}
}
- if (findBase.getChildCount() > 0)
+ else
{
- for (int i = 0, childCount = findBase.getChildCount(); i < childCount; i++)
- {
- UIComponent find = findBase.getChildren().get(i).findComponent(innerExpr);
- if (find != null)
- {
- return find;
- }
- }
+ //At this point, findBase has a NamingContainer that does not match with the id.
+ //We need to scan from this component the full expression.
+ return _ComponentUtils.innerFindComponent(findBase, expr, null);
}
- return null;
}
/**
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentUtils.java?rev=1157584&r1=1157583&r2=1157584&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentUtils.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentUtils.java Sun Aug 14 18:06:51 2011
@@ -150,6 +150,71 @@ class _ComponentUtils
return null;
}
+
+ static UIComponent innerFindComponent(UIComponent parent, String id, String innerExpr)
+ {
+ if (parent.getFacetCount() > 0)
+ {
+ for (UIComponent facet : parent.getFacets().values())
+ {
+ if (id.equals(facet.getId()))
+ {
+ if (innerExpr == null)
+ {
+ return facet;
+ }
+ else if (facet instanceof NamingContainer)
+ {
+ UIComponent find = facet.findComponent(innerExpr);
+ if (find != null)
+ {
+ return find;
+ }
+ }
+ }
+ else
+ {
+ UIComponent find = innerFindComponent(facet, id, innerExpr);
+ if (find != null)
+ {
+ return find;
+ }
+ }
+ }
+ }
+ if (parent.getChildCount() > 0)
+ {
+ for (int i = 0, childCount = parent.getChildCount(); i < childCount; i++)
+ {
+ UIComponent child = parent.getChildren().get(i);
+ if (id.equals(child.getId()))
+ {
+ if (innerExpr == null)
+ {
+ return child;
+ }
+ else if (child instanceof NamingContainer)
+ {
+ UIComponent find = child.findComponent(innerExpr);
+ if (find != null)
+ {
+ return find;
+ }
+ }
+ }
+ else
+ {
+ UIComponent find = innerFindComponent(child, id, innerExpr);
+ if (find != null)
+ {
+ return find;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
/*
* Return true if the specified component matches the provided id. This needs some quirks to handle components whose