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/10/08 23:59:45 UTC
svn commit: r823343 - in /myfaces/core/branches/1.2.x/api/src:
main/java/javax/faces/component/UIData.java
test/java/javax/faces/component/UIDataTest.java
Author: lu4242
Date: Thu Oct 8 21:59:45 2009
New Revision: 823343
URL: http://svn.apache.org/viewvc?rev=823343&view=rev
Log:
MYFACES-2370 'invokeOnComponent' method in UIData does not properly process <h:column> header/footer facets (Thanks to Jakob Korherr for provide this patch)
Modified:
myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/UIData.java
myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/component/UIDataTest.java
Modified: myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/UIData.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/UIData.java?rev=823343&r1=823342&r2=823343&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/UIData.java (original)
+++ myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/component/UIData.java Thu Oct 8 21:59:45 2009
@@ -320,42 +320,69 @@
{
return returnValue;
}
-
+
//Now we have to check if it is searching an inner component
String baseClientId = super.getClientId(context);
-
- //First check if the clientId starts with the baseClientId of
- //this component, to check if continue trying to find the component
- //inside the children of this component.
- if (clientId.matches(baseClientId + ":[0-9]+:.*"))
- {
-
- String subId = clientId.substring(baseClientId.length() + 1);
- String clientRow = subId.substring(0, subId.indexOf(':'));
-
- //Now we save the current position
- int oldRow = this.getRowIndex();
-
- //The conversion is safe, because its already checked on the
- //regular expresion
- this.setRowIndex(Integer.parseInt(clientRow));
-
- for (Iterator<UIComponent> it1 = getChildren().iterator(); !returnValue && it1.hasNext();)
+
+ // is the component an inner component?
+ if (clientId.startsWith(baseClientId))
+ {
+ // Check if the clientId for the component, which we
+ // are looking for, has a rowIndex attached
+ if (clientId.matches(baseClientId + ":[0-9]+:.*"))
+ {
+ String subId = clientId.substring(baseClientId.length() + 1);
+ String clientRow = subId.substring(0, subId.indexOf(':'));
+
+ //Now we save the current position
+ int oldRow = this.getRowIndex();
+
+ // try-finally --> make sure, that the old row index is restored
+ try
+ {
+ //The conversion is safe, because its already checked on the
+ //regular expresion
+ this.setRowIndex(Integer.parseInt(clientRow));
+
+ // check, if the row is available
+ if (!isRowAvailable())
+ {
+ return false;
+ }
+
+ for (Iterator<UIComponent> it1 = getChildren().iterator();
+ !returnValue && it1.hasNext();)
+ {
+ //recursive call to find the component
+ returnValue = it1.next().invokeOnComponent(context, clientId, callback);
+ }
+ }
+ finally
+ {
+ //Restore the old position. Doing this prevent
+ //side effects.
+ this.setRowIndex(oldRow);
+ }
+ }
+ else
{
- //recursive call to find the component
- UIComponent child = it1.next();
- returnValue = child.invokeOnComponent(context, clientId, callback);
+ // MYFACES-2370: search the component in the childrens' facets too.
+ // We have to check the childrens' facets here, because in MyFaces
+ // the rowIndex is not attached to the clientId for the children of
+ // facets of the UIColumns. However, in RI the rowIndex is
+ // attached to the clientId of UIColumns' Facets' children.
+ for (Iterator<UIComponent> itChildren = this.getChildren().iterator();
+ !returnValue && itChildren.hasNext();)
+ {
+ // process the child's facets
+ for (Iterator<UIComponent> itChildFacets = itChildren.next().getFacets().values().iterator();
+ !returnValue && itChildFacets.hasNext();)
+ {
+ //recursive call to find the component
+ returnValue = itChildFacets.next().invokeOnComponent(context, clientId, callback);
+ }
+ }
}
-
- //Restore the old position. Doing this prevent
- //side effects.
- this.setRowIndex(oldRow);
- }
- else
- {
- //The component that matches this clientId must be outside
- //of this component
- return false;
}
return returnValue;
Modified: myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/component/UIDataTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/component/UIDataTest.java?rev=823343&r1=823342&r2=823343&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/component/UIDataTest.java (original)
+++ myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/component/UIDataTest.java Thu Oct 8 21:59:45 2009
@@ -18,14 +18,15 @@
*/
package javax.faces.component;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;
+
import org.apache.myfaces.Assert;
import org.apache.myfaces.TestRunner;
import org.apache.shale.test.base.AbstractJsfTestCase;
import org.easymock.classextension.EasyMock;
import org.easymock.classextension.IMocksControl;
-import javax.faces.render.Renderer;
-
/**
* @author Mathias Broekelmann (latest modification by $Author$)
* @version $Revision$ $Date$
@@ -84,10 +85,39 @@
/**
* Test method for
* {@link javax.faces.component.UIData#invokeOnComponent(javax.faces.context.FacesContext, java.lang.String, javax.faces.component.ContextCallback)}.
+ * Tests, if invokeOnComponent also checks the facets of the h:column children (MYFACES-2370)
*/
public void testInvokeOnComponentFacesContextStringContextCallback()
{
- // TODO
+ /**
+ * Concrete class of ContextCallback needed to test invokeOnComponent.
+ * @author Jakob Korherr
+ */
+ final class MyContextCallback implements ContextCallback
+ {
+
+ private boolean invoked = false;
+
+ public void invokeContextCallback(FacesContext context,
+ UIComponent target)
+ {
+ this.invoked = true;
+ }
+
+ }
+
+ UIComponent facet = new UIOutput();
+ facet.setId("facet");
+ UIColumn column = new UIColumn();
+ column.setId("column");
+ column.getFacets().put("header", facet);
+ _testImpl.setId("uidata");
+ _testImpl.getChildren().add(column);
+
+ MyContextCallback callback = new MyContextCallback();
+ _testImpl.invokeOnComponent(facesContext, facet.getClientId(facesContext), callback);
+ // the callback should have been invoked
+ assertTrue(callback.invoked);
}
/**