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 2010/01/12 18:28:25 UTC
svn commit: r898429 - in /myfaces/core/trunk/impl/src:
main/java/org/apache/myfaces/view/facelets/tag/jsf/
test/java/org/apache/myfaces/view/facelets/tag/jsf/core/
test/java/org/apache/myfaces/view/facelets/tag/jsf/html/
Author: lu4242
Date: Tue Jan 12 17:28:24 2010
New Revision: 898429
URL: http://svn.apache.org/viewvc?rev=898429&view=rev
Log:
MYFACES-2435 f:facet can have more than one child (Thanks to Jakob Korherr for this patch)
Modified:
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
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreTestCase.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/html/DataTableTestCase.java
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=898429&r1=898428&r2=898429&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 Tue Jan 12 17:28:24 2010
@@ -117,7 +117,7 @@
*/
public static UIComponent findChildByTagId(UIComponent parent, String id)
{
- Iterator<UIComponent> itr = parent.getFacetsAndChildren();
+ Iterator<UIComponent> itr = parent.getChildren().iterator();
while (itr.hasNext())
{
UIComponent child = itr.next();
@@ -126,6 +126,30 @@
return child;
}
}
+ itr = parent.getFacets().values().iterator();
+ while (itr.hasNext())
+ {
+ UIComponent facet = itr.next();
+ // check if this is a dynamically generated UIPanel
+ if (Boolean.TRUE.equals(facet.getAttributes()
+ .get(ComponentTagHandlerDelegate.FACET_CREATED_UIPANEL_MARKER)))
+ {
+ // only check the children and facets of the panel
+ Iterator<UIComponent> itr2 = facet.getFacetsAndChildren();
+ while (itr2.hasNext())
+ {
+ UIComponent child = itr2.next();
+ if (id.equals(child.getAttributes().get(MARK_CREATED)))
+ {
+ return child;
+ }
+ }
+ }
+ else if (id.equals(facet.getAttributes().get(MARK_CREATED)))
+ {
+ return facet;
+ }
+ }
return null;
}
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=898429&r1=898428&r2=898429&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 Tue Jan 12 17:28:24 2010
@@ -31,6 +31,7 @@
import javax.faces.component.ActionSource;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIPanel;
import javax.faces.component.UniqueIdVendor;
import javax.faces.component.ValueHolder;
import javax.faces.component.behavior.ClientBehaviorHolder;
@@ -67,6 +68,13 @@
{
//private final static Logger log = Logger.getLogger("facelets.tag.component");
private final static Logger log = Logger.getLogger(ComponentTagHandlerDelegate.class.getName());
+
+ /**
+ * The UIPanel components, which are dynamically generated to serve as a container for
+ * facets with multiple non panel children, are marked with this attribute.
+ * This constant is duplicate in javax.faces.webapp.UIComponentClassicTagBase
+ */
+ public final static String FACET_CREATED_UIPANEL_MARKER = "org.apache.myfaces.facet.createdUIPanel";
private final ComponentHandler _delegate;
@@ -208,6 +216,18 @@
{
parent.getChildren().remove(c);
}
+ else
+ {
+ UIComponent facet = parent.getFacet(facetName);
+ if (Boolean.TRUE.equals(facet.getAttributes().get(FACET_CREATED_UIPANEL_MARKER)))
+ {
+ facet.getChildren().remove(c);
+ }
+ else
+ {
+ parent.getFacets().remove(facetName);
+ }
+ }
}
if (c instanceof ClientBehaviorHolder && !UIComponent.isCompositeComponent(c))
@@ -240,7 +260,59 @@
}
else
{
- parent.getFacets().put(facetName, c);
+ // facets now can have multiple children and the direct
+ // child of a facet is always an UIPanel (since 2.0)
+ UIComponent facet = parent.getFacets().get(facetName);
+ boolean facetChanged = false;
+
+ if (facet == null)
+ {
+ // if our component is an instance of UIPanel, use it
+ if (c instanceof UIPanel)
+ {
+ facet = c;
+ }
+ else
+ {
+ // create a new UIPanel and add c as child
+ facet = createFacetUIPanel(facesContext);
+ facet.getChildren().add(c);
+ }
+ facetChanged = true;
+ }
+ else if (!(facet instanceof UIPanel))
+ {
+ // there is a facet, but it is not an instance of UIPanel
+ UIComponent child = facet;
+ facet = createFacetUIPanel(facesContext);
+ facet.getChildren().add(child);
+ facet.getChildren().add(c);
+ facetChanged = true;
+ }
+ else
+ {
+ // we have a facet, which is an instance of UIPanel at this point
+ // check if it is a facet marked UIPanel
+ if (Boolean.TRUE.equals(facet.getAttributes().get(FACET_CREATED_UIPANEL_MARKER)))
+ {
+ facet.getChildren().add(c);
+ }
+ else
+ {
+ // the facet is an instance of UIPanel, but it is not marked,
+ // so we have to create a new UIPanel and store this one in it
+ UIComponent oldPanel = facet;
+ facet = createFacetUIPanel(facesContext);
+ facet.getChildren().add(oldPanel);
+ facet.getChildren().add(c);
+ facetChanged = true;
+ }
+ }
+
+ if (facetChanged)
+ {
+ parent.getFacets().put(facetName, facet);
+ }
}
if (c instanceof UniqueIdVendor)
@@ -435,5 +507,20 @@
// By default, all default validators should be added
return true;
}
+
+ /**
+ * Create a new UIPanel for the use as a dynamically
+ * created container for multiple children in a facet.
+ * Duplicate in javax.faces.webapp.UIComponentClassicTagBase.
+ * @param facesContext
+ * @return
+ */
+ private UIComponent createFacetUIPanel(FacesContext facesContext)
+ {
+ UIComponent panel = facesContext.getApplication().createComponent(UIPanel.COMPONENT_TYPE);
+ panel.setId(facesContext.getViewRoot().createUniqueId());
+ panel.getAttributes().put(FACET_CREATED_UIPANEL_MARKER, Boolean.TRUE);
+ return panel;
+ }
}
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreTestCase.java?rev=898429&r1=898428&r2=898429&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreTestCase.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreTestCase.java Tue Jan 12 17:28:24 2010
@@ -31,6 +31,7 @@
import javax.faces.component.UIGraphic;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
+import javax.faces.component.UIPanel;
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.component.html.HtmlDataTable;
@@ -61,6 +62,8 @@
{
application.addComponent(UIViewRoot.COMPONENT_TYPE, UIViewRoot.class
.getName());
+ application.addComponent(UIPanel.COMPONENT_TYPE,
+ UIPanel.class.getName());
application.addComponent(HtmlCommandLink.COMPONENT_TYPE,
HtmlCommandLink.class.getName());
application.addComponent(HtmlGraphicImage.COMPONENT_TYPE,
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/html/DataTableTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/html/DataTableTestCase.java?rev=898429&r1=898428&r2=898429&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/html/DataTableTestCase.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/html/DataTableTestCase.java Tue Jan 12 17:28:24 2010
@@ -22,6 +22,7 @@
import javax.faces.component.UIColumn;
import javax.faces.component.UIData;
import javax.faces.component.UIOutput;
+import javax.faces.component.UIPanel;
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlColumn;
import javax.faces.component.html.HtmlDataTable;
@@ -42,6 +43,8 @@
{
application.addComponent(UIViewRoot.COMPONENT_TYPE, UIViewRoot.class
.getName());
+ application.addComponent(UIPanel.COMPONENT_TYPE,
+ UIPanel.class.getName());
application.addComponent(HtmlDataTable.COMPONENT_TYPE,
HtmlDataTable.class.getName());
application.addComponent(UIColumn.COMPONENT_TYPE,