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/22 04:02:39 UTC
svn commit: r901965 - in
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets:
compiler/AbstractUIHandler.java tag/jsf/ComponentSupport.java
tag/jsf/ComponentTagHandlerDelegate.java
Author: lu4242
Date: Fri Jan 22 03:02:38 2010
New Revision: 901965
URL: http://svn.apache.org/viewvc?rev=901965&view=rev
Log:
MYFACES-2435 f:facet can have more than one child (fix use of UIInstruction inside f:facet)
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/AbstractUIHandler.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/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/AbstractUIHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/AbstractUIHandler.java?rev=901965&r1=901964&r2=901965&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/AbstractUIHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/AbstractUIHandler.java Fri Jan 22 03:02:38 2010
@@ -23,6 +23,7 @@
import javax.faces.view.facelets.FaceletHandler;
import javax.faces.view.facelets.TextHandler;
+import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
import org.apache.myfaces.view.facelets.tag.jsf.core.FacetHandler;
public abstract class AbstractUIHandler implements FaceletHandler, TextHandler
@@ -38,7 +39,7 @@
}
else
{
- parent.getFacets().put(facetName, c);
+ ComponentSupport.addFacet(ctx, parent, c, facetName);
}
}
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=901965&r1=901964&r2=901965&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 Fri Jan 22 03:02:38 2010
@@ -26,6 +26,7 @@
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIPanel;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.view.facelets.FaceletContext;
@@ -42,6 +43,13 @@
private final static String MARK_DELETED = "org.apache.myfaces.view.facelets.MARK_DELETED";
public final static String MARK_CREATED = "org.apache.myfaces.view.facelets.MARK_ID";
+
+ /**
+ * 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";
/**
* Used in conjunction with markForDeletion where any UIComponent marked will be removed.
@@ -132,7 +140,7 @@
UIComponent facet = itr.next();
// check if this is a dynamically generated UIPanel
if (Boolean.TRUE.equals(facet.getAttributes()
- .get(ComponentTagHandlerDelegate.FACET_CREATED_UIPANEL_MARKER)))
+ .get(FACET_CREATED_UIPANEL_MARKER)))
{
// only check the children and facets of the panel
Iterator<UIComponent> itr2 = facet.getFacetsAndChildren();
@@ -322,4 +330,89 @@
{
return component != null && component.getParent() == null;
}
+
+ /**
+ * 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 static 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;
+ }
+
+ public static void addFacet(FaceletContext ctx, UIComponent parent, UIComponent c, String facetName)
+ {
+ // 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(ctx.getFacesContext());
+ 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(ctx.getFacesContext());
+ 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(ctx.getFacesContext());
+ facet.getChildren().add(oldPanel);
+ facet.getChildren().add(c);
+ facetChanged = true;
+ }
+ }
+
+ if (facetChanged)
+ {
+ parent.getFacets().put(facetName, facet);
+ }
+ }
+
+ public static void removeFacet(FaceletContext ctx, UIComponent parent, UIComponent c, String facetName)
+ {
+ 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);
+ }
+ }
}
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=901965&r1=901964&r2=901965&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 Fri Jan 22 03:02:38 2010
@@ -69,14 +69,7 @@
{
//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;
private final String _componentType;
@@ -219,15 +212,7 @@
}
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);
- }
+ ComponentSupport.removeFacet(ctx, parent, c, facetName);
}
}
@@ -261,59 +246,7 @@
}
else
{
- // 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);
- }
+ ComponentSupport.addFacet(ctx, parent, c, facetName);
}
if (c instanceof UniqueIdVendor)
@@ -584,20 +517,4 @@
// 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;
- }
-
}