You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jw...@apache.org on 2008/02/26 02:46:15 UTC
svn commit: r631062 - in
/myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src:
main/java/org/apache/myfaces/trinidad/render/
main/java/org/apache/myfaces/trinidad/util/
test/java/org/apache/myfaces/trinidad/render/
Author: jwaldman
Date: Mon Feb 25 17:46:12 2008
New Revision: 631062
URL: http://svn.apache.org/viewvc?rev=631062&view=rev
Log:
TRINIDAD-936 changed the partialTrigger syntax so '::' pops out of naming container.
enhance performance of RenderUtils.getRelativeId.
changed relativeId parameter to scopedId since that is the terminology that we use. We have
three types of ids: id, clientId, and scopedId.
trunk_1.2.x
Modified:
myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/RenderUtils.java
myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java
myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/test/java/org/apache/myfaces/trinidad/render/RenderUtilsTest.java
Modified: myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/RenderUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/RenderUtils.java?rev=631062&r1=631061&r2=631062&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/RenderUtils.java (original)
+++ myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/RenderUtils.java Mon Feb 25 17:46:12 2008
@@ -112,12 +112,14 @@
* <p>
* e.g., given this hierarchy
* <br/>
- * <f:subview id="aaa"><f:subview id="xxx"><br/>
+ * <f:subview id="aaa">
+ * <f:subview id="xxx"><br/>
<tr:chooseColor id="cp1" .../><br/>
<f:subview id="yyy"><br/>
<tr:inputColor id="sic1" chooseId="::cp1" .../><br/>
</f:subview><br/>
- </f:subview></f:subview><br/>
+ </f:subview>
+ </f:subview><br/>
</p>
<p>
* The 'from' component is the inputColor component.
@@ -128,7 +130,7 @@
* </p>
* <p>
* It does not assume that the target component can be located, although it does
- * check. If it can't be found, returns the correct relativeId anyway.
+ * check. If it can't be found, it returns the correct relativeId anyway.
* </p>
* <p>
* A relativeId starting with
@@ -146,25 +148,26 @@
* </p>
* @param context
* @param from the component to search relative to
- * @param relativeId the relative path from the 'from' component
- * to the component to find
+ * @param scopedId the relative id path from the 'from' component to the
+ * component to find
* @return the clientId for the 'relative' component.
- @see ComponentUtils.findRelativeComponent(from, relativeId)
+ * @see ComponentUtils#findRelativeComponent
+ * @see javax.faces.component.UIComponent#findComponent
*/
public static String getRelativeId(
FacesContext context,
UIComponent from,
- String relativeId)
+ String scopedId)
{
if (from == null)
return null;
- if ((relativeId == null) || (relativeId.length() == 0))
+ if ((scopedId == null) || (scopedId.length() == 0))
return null;
// Figure out how many colons
- int colonCount = _getColonCount(relativeId);
+ int colonCount = _getColonCount(scopedId);
// colonCount == 0: fully relative
// colonCount == 1: absolute
@@ -172,7 +175,17 @@
// the naming container (to the view root, if naming containers run out)
if (colonCount == 1)
- return relativeId.substring(1);
+ return scopedId.substring(1);
+ if (colonCount == 0 && !(from instanceof NamingContainer))
+ {
+ // we do it the fast way if there
+ // are no colons and the from isn't a NamingContainer.
+ // the reason is this use case hasn't changed between the previous
+ // logic and the current logic for finding the component, so it
+ // is already backward compatible, and therefore we don't have to
+ // call the findComponent code for backward compatibility.
+ return _getRelativeId(context, from, scopedId, colonCount);
+ }
//
// We need to make it backward compatible, and
@@ -181,25 +194,23 @@
// it can't be found. Plus, findRelativeComponent code has
// backward compatibilty built in.
UIComponent component =
- ComponentUtils.findRelativeComponent(from, relativeId);
+ ComponentUtils.findRelativeComponent(from, scopedId);
if (component == null && from instanceof NamingContainer)
{
- component = ComponentUtils.findRelativeComponent(from.getParent(), relativeId);
+ component = ComponentUtils.findRelativeComponent(from.getParent(), scopedId);
if (component != null)
{
- // TODO Log warning
_LOG.warning("DEPRECATED_RELATIVE_ID_SYNTAX",
- new Object[] {relativeId, from});
+ new Object[] {scopedId, from});
}
}
// the component wasn't found, but go ahead and return something smart
if (component == null)
{
- // TODO LOG warning
_LOG.warning("RELATIVE_ID_NOT_FOUND",
- new Object[] {relativeId, from});
- return _getRelativeId(context, from, relativeId, colonCount);
+ new Object[] {scopedId, from});
+ return _getRelativeId(context, from, scopedId, colonCount);
}
else
{
@@ -245,7 +256,8 @@
from = _getParentNamingContainer(from);
}
-
+ // assumption is no one but the parent naming container modifies its
+ // client id
if (from == null)
return relativeId;
else
@@ -261,7 +273,7 @@
// Given a component, get its naming container. If the component
// is a naming container, it will get its naming container.
// This is different than the one in ComponentUtils. This one
- // returns null if there are no more NamingContainers. The other one
+ // returns null if there are no NamingContainers. The other one
// returns the ViewRoot.
private static UIComponent _getParentNamingContainer (
UIComponent from)
Modified: myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java?rev=631062&r1=631061&r2=631062&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java (original)
+++ myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java Mon Feb 25 17:46:12 2008
@@ -333,25 +333,27 @@
* </p>
*
* @param from the component to search relative to
- * @param relativeId the relative path to the component to find
+ * @param scopedId the relative id path from the 'from' component to the
+ * component to find
* @return the component if found, null otherwise
- * @see RenderUtils.getRelativeId(from, relativeId)
+ * @see org.apache.myfaces.trinidad.render.RenderUtils#getRelativeId
+ * @see javax.faces.component.UIComponent#findComponent
*/
public static UIComponent findRelativeComponent(
UIComponent from,
- String relativeId)
+ String scopedId)
{
if (from == null)
return null;
UIComponent originalFrom = from;
- String originalRelativeId = relativeId;
+ String originalRelativeId = scopedId;
- int idLength = relativeId.length();
+ int idLength = scopedId.length();
// Figure out how many colons
int colonCount = 0;
while (colonCount < idLength)
{
- if (relativeId.charAt(colonCount) != NamingContainer.SEPARATOR_CHAR)
+ if (scopedId.charAt(colonCount) != NamingContainer.SEPARATOR_CHAR)
break;
colonCount++;
}
@@ -362,7 +364,7 @@
// the naming container (to the view root, if naming containers run out)
if (colonCount > 1)
{
- relativeId = relativeId.substring(colonCount);
+ scopedId = scopedId.substring(colonCount);
// if the component is not a NamingContainer, then we need to
// get the component's naming container and set this as the 'from'.
@@ -380,7 +382,7 @@
}
}
- UIComponent found = from.findComponent(relativeId);
+ UIComponent found = from.findComponent(scopedId);
if (found != null)
return found;
else
Modified: myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/test/java/org/apache/myfaces/trinidad/render/RenderUtilsTest.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/test/java/org/apache/myfaces/trinidad/render/RenderUtilsTest.java?rev=631062&r1=631061&r2=631062&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/test/java/org/apache/myfaces/trinidad/render/RenderUtilsTest.java (original)
+++ myfaces/trinidad/branches/1.2.6.1-branch/trinidad-api/src/test/java/org/apache/myfaces/trinidad/render/RenderUtilsTest.java Mon Feb 25 17:46:12 2008
@@ -107,7 +107,7 @@
String relativeId =
RenderUtils.getRelativeId(null, button1, "table1");
- assertEquals("table1_Client", relativeId);
+ assertEquals("table1", relativeId);
relativeId =
RenderUtils.getRelativeId(null, button1, ":table1");