myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r991417 - in /myfaces/core/trunk/impl/src: main/java/org/apache/myfaces/view/facelets/ main/java/org/apache/myfaces/view/facelets/compiler/ main/java/org/apache/myfaces/view/facelets/impl/ main/java/org/apache/myfaces/view/facelets/tag/jsf/...
Date Wed, 01 Sep 2010 01:55:21 GMT
Author: lu4242
Date: Wed Sep  1 01:55:20 2010
New Revision: 991417

URL: http://svn.apache.org/viewvc?rev=991417&view=rev
Log:
MYFACES-2774 Remove MARK_DELETED attribute from the component (Thanks to Marius Petoi for
his help with this patch)

Added:
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jstl/core/CifTestCase.java
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jstl/core/if2.xhtml
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jstl/core/if3.xhtml
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFacelet.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.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/FaceletCompositionContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java?rev=991417&r1=991416&r2=991417&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java
Wed Sep  1 01:55:20 2010
@@ -91,20 +91,19 @@ abstract public class FaceletComposition
      * This could be used by InsertChildrenHandler and InsertFacetHandler to retrieve the
current
      * composite component to be applied.
      * 
-     * @since 2.0
-     * @param facesContext
+     * @since 2.0.1
      * @return
      */
     public abstract UIComponent getCompositeComponentFromStack();
 
     /**
-     * @since 2.0
+     * @since 2.0.1
      * @param parent
      */
     public abstract void pushCompositeComponentToStack(UIComponent parent);
 
     /**
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract void popCompositeComponentToStack();
     
@@ -114,79 +113,79 @@ abstract public class FaceletComposition
      * Note that facelets tree is built from leafs to root, that means use UIComponent.getParent()
does not
      * always return parent components.
      * 
-     * @since 2.0
+     * @since 2.0.1
      * @return
      */
     public abstract UniqueIdVendor getUniqueIdVendorFromStack();
 
     /**
-     * @since 2.0
+     * @since 2.0.1
      * @param parent
      */
     public abstract void pushUniqueIdVendorToStack(UniqueIdVendor parent);
 
     /**
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract void popUniqueIdVendorToStack();
     
     /**
      * Gets the top of the validationGroups stack.
      * @return
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract String getFirstValidationGroupFromStack();
     
     /**
      * Removes top of stack.
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract void popValidationGroupsToStack();
     
     /**
      * Pushes validationGroups to the stack.
      * @param validationGroups
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract void pushValidationGroupsToStack(String validationGroups);
     
     /**
      * Gets all validationIds on the stack.
      * @return
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract Iterator<String> getExcludedValidatorIds();
     
     /**
      * Removes top of stack.
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract void popExcludedValidatorIdToStack();
     
     /**
      * Pushes validatorId to the stack of excluded validatorIds.
      * @param validatorId
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract void pushExcludedValidatorIdToStack(String validatorId);
     
     /**
      * Gets all validationIds on the stack.
      * @return
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract Iterator<String> getEnclosingValidatorIds();
     
     /**
      * Removes top of stack.
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract void popEnclosingValidatorIdToStack();
     
     /**
      * Pushes validatorId to the stack of all enclosing validatorIds.
      * @param validatorId
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract void pushEnclosingValidatorIdToStack(String validatorId);
     
@@ -195,7 +194,7 @@ abstract public class FaceletComposition
      * and adding/removing components under c:if or c:forEach or not.
      * 
      * @return
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract boolean isRefreshingTransientBuild();
     
@@ -204,7 +203,7 @@ abstract public class FaceletComposition
      * all components must call UIComponent.markInitialState.
      * 
      * @return
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract boolean isMarkInitialState();
     
@@ -219,7 +218,7 @@ abstract public class FaceletComposition
      *    (c:if, c:forEach...)
      * 
      * @return
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract boolean isRefreshTransientBuildOnPSS();
     
@@ -227,10 +226,14 @@ abstract public class FaceletComposition
      * Check if we are using partial state saving on this view
      * 
      * @return
-     * @since 2.0
+     * @since 2.0.1
      */
     public abstract boolean isUsingPSSOnThisView();
     
+    /**
+     * @since 2.0.1
+     * @return
+     */
     public abstract boolean isMarkInitialStateAndIsRefreshTransientBuildOnPSS();
 
     /**
@@ -240,6 +243,7 @@ abstract public class FaceletComposition
      * Tag Handlers exposing attached objects should call this method to expose them when
the
      * parent to be applied is a composite components.
      *
+     * @since 2.0.2
      * @param compositeComponentParent
      * @param handler
      */
@@ -248,15 +252,36 @@ abstract public class FaceletComposition
     /**
      * Remove from the composite component parent the list of attached handlers.
      * 
+     * @since 2.0.2
      * @param compositeComponentParent
      */
     public abstract void removeAttachedObjectHandlers(UIComponent compositeComponentParent);
 
     /**
      * Retrieve the list of object handlers attached to a composite component parent. 
-     *
+     * 
+     * @since 2.0.2
      * @param compositeComponentParent
      */
     public abstract List<AttachedObjectHandler> getAttachedObjectHandlers(UIComponent
compositeComponentParent);
+
+    /**
+     * Marks all direct children and Facets with an attribute for deletion.
+     *
+     * @since 2.0.2
+     * @see #finalizeForDeletion(FaceletCompositionContext, UIComponent)
+     * @param component
+     *            UIComponent to mark
+     */
+    public abstract void markForDeletion(UIComponent component);
     
+    /**
+     * Used in conjunction with markForDeletion where any UIComponent marked will be removed.
+     * 
+     * @since 2.0.2
+     * @param component
+     *            UIComponent to finalize
+     */
+    public abstract void finalizeForDeletion(UIComponent component);
+
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java?rev=991417&r1=991416&r2=991417&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
Wed Sep  1 01:55:20 2010
@@ -142,7 +142,7 @@ final class UIInstructionHandler extends
             {
                 componentFound = true;
                 // mark all children for cleaning
-                ComponentSupport.markForDeletion(c);
+                mctx.markForDeletion(c);
             }
             else
             {
@@ -189,7 +189,7 @@ final class UIInstructionHandler extends
             // finish cleaning up orphaned children
             if (componentFound)
             {
-                ComponentSupport.finalizeForDeletion(c);
+                mctx.finalizeForDeletion(c);
                 if (!componentFoundInserted)
                 {
                     if (mctx.isRefreshingTransientBuild())

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFacelet.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFacelet.java?rev=991417&r1=991416&r2=991417&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFacelet.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFacelet.java
Wed Sep  1 01:55:20 2010
@@ -139,9 +139,9 @@ final class DefaultFacelet extends Abstr
             }
             
             this.refresh(parent);
-            ComponentSupport.markForDeletion(parent);
+            myFaceletContext.markForDeletion(parent);
             _root.apply(ctx, parent);
-            ComponentSupport.finalizeForDeletion(parent);
+            myFaceletContext.finalizeForDeletion(parent);
             this.markApplied(parent);
             
             // remove the UniqueIdVendor from the stack again
@@ -383,16 +383,17 @@ final class DefaultFacelet extends Abstr
         // push the parent as a UniqueIdVendor to the stack here,
         // if there is no UniqueIdVendor on the stack yet
         boolean pushedUniqueIdVendor = false;
+        FaceletCompositionContext mctx = ctx.getFaceletCompositionContext();
         if (parent instanceof UniqueIdVendor && ctx.getFaceletCompositionContext().getUniqueIdVendorFromStack()
== null)
         {
-            ctx.getFaceletCompositionContext().pushUniqueIdVendorToStack((UniqueIdVendor)
parent);
+            mctx.pushUniqueIdVendorToStack((UniqueIdVendor) parent);
             pushedUniqueIdVendor = true;
         }
         
         this.refresh(parent);
-        ComponentSupport.markForDeletion(parent);
+        mctx.markForDeletion(parent);
         f._root.apply(new DefaultFaceletContext( (DefaultFaceletContext)ctx, f, true), parent);
-        ComponentSupport.finalizeForDeletion(parent);
+        mctx.finalizeForDeletion(parent);
         this.markApplied(parent);
         
         // remove the UniqueIdVendor from the stack again

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java?rev=991417&r1=991416&r2=991417&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java
Wed Sep  1 01:55:20 2010
@@ -33,6 +33,7 @@ import javax.faces.view.AttachedObjectHa
 import org.apache.myfaces.view.facelets.FaceletCompositionContext;
 import org.apache.myfaces.view.facelets.FaceletFactory;
 import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
+import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
 
 /**
  * @since 2.0.1
@@ -62,8 +63,14 @@ public class FaceletCompositionContextIm
     private Boolean _refreshTransientBuildOnPSS;
     
     private Boolean _usingPSSOnThisView;
+
+    private List<Map<String, UIComponent>> _componentsMarkedForDeletion;
+    
+    private int _deletionLevel;
     
     private final Map<UIComponent, List<AttachedObjectHandler>> _attachedObjectHandlers;
+
+    private static final String VIEWROOT_FACELET_ID = "oam.VIEW_ROOT";
     
     public FaceletCompositionContextImpl(FaceletFactory factory, FacesContext facesContext)
     {
@@ -71,6 +78,8 @@ public class FaceletCompositionContextIm
         _factory = factory;
         _facesContext = facesContext;
         _attachedObjectHandlers = new HashMap<UIComponent, List<AttachedObjectHandler>>();
+        _componentsMarkedForDeletion = new ArrayList<Map<String,UIComponent>>();
+        _deletionLevel = -1;
     }
 
     public FaceletFactory getFaceletFactory()
@@ -89,6 +98,7 @@ public class FaceletCompositionContextIm
         _excludedValidatorIdsStack = null;
         _uniqueIdVendorStack = null;
         _validationGroupsStack = null;
+        _componentsMarkedForDeletion = null;
     }
    
     @Override
@@ -355,4 +365,165 @@ public class FaceletCompositionContextIm
     {
         return _attachedObjectHandlers.get(compositeComponentParent);
     }
+
+    /**
+     * Add a level of components marked for deletion.
+     *
+     * @param levelSize the number of elements on this level.
+     */
+    private void increaseComponentLevelMarkedForDeletion()
+    {
+        _deletionLevel++;
+        if (_componentsMarkedForDeletion.size() <= _deletionLevel)
+        {
+            _componentsMarkedForDeletion.add(new HashMap<String, UIComponent>());
+            
+        }
+    }
+
+    /**
+     * Remove the last component level from the components marked to be deleted. The components
are removed
+     * from this list because they are deleted from the tree. This is done in ComponentSupport.finalizeForDeletion.
+     *
+     * @return the array of components that are removed.
+     */
+    private void decreaseComponentLevelMarkedForDeletion()
+    {
+        //The common case is this co
+        if (!_componentsMarkedForDeletion.get(_deletionLevel).isEmpty())
+        {
+            _componentsMarkedForDeletion.get(_deletionLevel).clear();
+        }
+        _deletionLevel--;
+    }
+
+    /** Mark a component to be deleted from the tree. The component to be deleted is addded
on the
+     * current level. This is done from ComponentSupport.markForDeletion
+     *
+     * @param component the component marked for deletion.
+     * @param index the index to add the component at.
+     */
+    private void markComponentForDeletion(String id , UIComponent component)
+    {
+        _componentsMarkedForDeletion.get(_deletionLevel).put(id, component);
+    }
+
+    /**
+     * Remove a component from the last level of components marked to be deleted.
+     *
+     * @param component the component to be removed.
+     */
+    private UIComponent removeComponentForDeletion(String id)
+    {
+        UIComponent removedComponent = _componentsMarkedForDeletion.get(_deletionLevel).remove(id);

+        if (removedComponent != null && _deletionLevel > 0)
+        {
+            _componentsMarkedForDeletion.get(_deletionLevel-1).remove(id);
+        }
+        return removedComponent;
+    }
+    
+    public void markForDeletion(UIComponent component)
+    {
+        increaseComponentLevelMarkedForDeletion();
+        
+        String id = (String) component.getAttributes().get(ComponentSupport.MARK_CREATED);
+        id = (id == null) ? VIEWROOT_FACELET_ID : id;
+        markComponentForDeletion(id, component);
+        
+        Map<String, UIComponent> facets = component.getFacets();
+        if (!facets.isEmpty())
+        {
+            for (Iterator<UIComponent> itr = facets.values().iterator(); itr.hasNext();)
+            {
+                UIComponent fc = itr.next();
+                id = (String) fc.getAttributes().get(ComponentSupport.MARK_CREATED);
+                if (id != null)
+                {
+                    markComponentForDeletion(id, fc);
+                }
+                else if (Boolean.TRUE.equals(fc.getAttributes().get(ComponentSupport.FACET_CREATED_UIPANEL_MARKER)))
+                {
+                    //Mark its children, but do not mark itself.
+                    for (Iterator<UIComponent> fciter = fc.getChildren().iterator();
fciter.hasNext();)
+                    {
+                        UIComponent child = fciter.next();
+                        id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
+                        if (id != null)
+                        {
+                            markComponentForDeletion(id, child);
+                        }
+                    }
+                }
+            }
+        }
+                
+        if (component.getChildCount() > 0)
+        {
+            for (Iterator<UIComponent> iter = component.getChildren().iterator(); iter.hasNext();)
+            {
+                UIComponent child = iter.next();
+                id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
+                if (id != null)
+                {
+                    markComponentForDeletion(id, child);
+                }
+            }
+        }
+    }
+    
+    public void finalizeForDeletion(UIComponent component)
+    {
+        String id = (String) component.getAttributes().get(ComponentSupport.MARK_CREATED);
+        id = (id == null) ? VIEWROOT_FACELET_ID : id;
+        // remove any existing marks of deletion
+        removeComponentForDeletion(id);
+        
+        // finally remove any children marked as deleted
+        if (component.getChildCount() > 0)
+        {
+            for (Iterator<UIComponent> iter = component.getChildren().iterator(); iter.hasNext();)
+            {
+                UIComponent child = iter.next();
+                id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED); 
+                if (id != null && removeComponentForDeletion(id) != null)
+                {
+                    iter.remove();
+                }
+            }
+        }
+
+        // remove any facets marked as deleted
+        Map<String, UIComponent> facets = component.getFacets();
+        if (!facets.isEmpty())
+        {
+            for (Iterator<UIComponent> itr = facets.values().iterator(); itr.hasNext();)
+            {
+                UIComponent fc = itr.next();
+                id = (String) fc.getAttributes().get(ComponentSupport.MARK_CREATED);
+                if (id != null && removeComponentForDeletion(id) != null)
+                {
+                    itr.remove();
+                }
+                else if ( id == null && Boolean.TRUE.equals(fc.getAttributes().get(ComponentSupport.FACET_CREATED_UIPANEL_MARKER)))
+                {
+                    for (Iterator<UIComponent> fciter = fc.getChildren().iterator();
fciter.hasNext();)
+                    {
+                        UIComponent child = fciter.next();
+                        id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
+                        if (id != null && removeComponentForDeletion(id) != null)
+                        {
+                            fciter.remove();
+                        }
+                    }
+                    if (fc.getChildCount() == 0)
+                    {
+                        itr.remove();
+                    }
+                }
+            }
+        }
+        
+        decreaseComponentLevelMarkedForDeletion();
+    }    
 }

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=991417&r1=991416&r2=991417&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
Wed Sep  1 01:55:20 2010
@@ -59,9 +59,11 @@ public final class ComponentSupport
     /**
      * Used in conjunction with markForDeletion where any UIComponent marked will be removed.
      * 
+     * @deprecated use FaceletCompositionContext.finalizeForDeletion
      * @param component
      *            UIComponent to finalize
      */
+    @Deprecated
     public static void finalizeForDeletion(UIComponent component)
     {
         // remove any existing marks of deletion
@@ -243,10 +245,12 @@ public final class ComponentSupport
     /**
      * Marks all direct children and Facets with an attribute for deletion.
      * 
+     * @deprecated use FaceletCompositionContext.markForDeletion
      * @see #finalizeForDeletion(UIComponent)
      * @param component
      *            UIComponent to mark
      */
+    @Deprecated
     public static void markForDeletion(UIComponent component)
     {
         // flag this component as deleted

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=991417&r1=991416&r2=991417&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
Wed Sep  1 01:55:20 2010
@@ -121,17 +121,17 @@ public class ComponentTagHandlerDelegate
      * <ol>
      * <li>First determines this UIComponent's id by calling {@link #getId(FaceletContext)
getId(FaceletContext)}.</li>
      * <li>Search the parent for an existing UIComponent of the id we just grabbed</li>
-     * <li>If found, {@link #markForDeletion(UIComponent) mark} its children for deletion.</li>
+     * <li>If found, {@link #FaceletCompositionContext.markForDeletion(UIComponent)
mark} its children for deletion.</li>
      * <li>If <i>not</i> found, call {@link #createComponent(FaceletContext)
createComponent}.
      * <ol>
-     * <li>Only here do we apply {@link TagHandler#setAttributes(FaceletContext, Object)
attributes}</li>
+     * <li>Only here do we apply {@link TagHandler#setAttributes(FaceletCompositionContext,
Object) attributes}</li>
      * <li>Set the UIComponent's id</li>
      * <li>Set the RendererType of this instance</li>
      * </ol>
      * </li>
      * <li>Now apply the nextHandler, passing the UIComponent we've created/found.</li>
      * <li>Now add the UIComponent to the passed parent</li>
-     * <li>Lastly, if the UIComponent already existed (found), then {@link #finalizeForDeletion(UIComponent)
finalize}
+     * <li>Lastly, if the UIComponent already existed (found), then {@link #finalizeForDeletion(FaceletCompositionContext,
UIComponent) finalize}
      * for deletion.</li>
      * </ol>
      * 
@@ -226,7 +226,7 @@ public class ComponentTagHandlerDelegate
             {
                 log.fine(_delegate.getTag() + " Component[" + id + "] Found, marking children
for cleanup");
             }
-            ComponentSupport.markForDeletion(c);
+            mctx.markForDeletion(c);
         }
         else
         {
@@ -297,7 +297,7 @@ public class ComponentTagHandlerDelegate
         // finish cleaning up orphaned children
         if (componentFound)
         {
-            ComponentSupport.finalizeForDeletion(c);
+            mctx.finalizeForDeletion(c);
 
             if (!componentFoundInserted)
             {
@@ -665,7 +665,7 @@ public class ComponentTagHandlerDelegate
      * Determine if the default Validator with the given validatorId should be added.
      *
      * @param validatorId The validatorId.
-     * @param context The FacesContext.
+     * @param facesContext The FacesContext.
      * @param mctx the AbstractFaceletContext
      * @param component The EditableValueHolder to which the validator should be added.
      * @return true if the Validator should be added, false otherwise.

Added: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jstl/core/CifTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jstl/core/CifTestCase.java?rev=991417&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jstl/core/CifTestCase.java
(added)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jstl/core/CifTestCase.java
Wed Sep  1 01:55:20 2010
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.view.facelets.tag.jstl.core;
+
+import java.util.Map;
+
+import javax.faces.application.StateManager;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+
+import org.apache.myfaces.shared_impl.config.MyfacesConfig;
+import org.apache.myfaces.view.facelets.FaceletTestCase;
+import org.apache.myfaces.view.facelets.bean.Employee;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class CifTestCase extends FaceletTestCase
+{
+
+    protected void setUpServletObjects() throws Exception
+    {
+        super.setUpServletObjects();
+        
+        servletContext.addInitParameter(StateManager.PARTIAL_STATE_SAVING_PARAM_NAME,
+                "true");
+        servletContext.addInitParameter(MyfacesConfig.INIT_PARAM_REFRESH_TRANSIENT_BUILD_ON_PSS,"true");
+    }
+    
+    @Test
+    public void testIf1() throws Exception
+    {
+        Map session = facesContext.getExternalContext().getSessionMap();
+        Employee e = new Employee();
+        session.put("employee", e);
+
+        UIViewRoot root = facesContext.getViewRoot();
+
+        // make sure the form is there
+        e.setManagement(true);
+        vdl.buildView(facesContext, root,"if2.xhtml");
+        UIComponent c = root.findComponent("form");
+        Assert.assertNotNull("form is null", c);
+        c = root.findComponent("start");
+        Assert.assertNotNull("start is null", c);
+        c = root.findComponent("end");
+        Assert.assertNotNull("end is null", c);
+               
+        
+        // now make sure it isn't
+        e.setManagement(false);
+        
+        //facesContext.setViewRoot(facesContext.getApplication().getViewHandler()
+        //        .createView(facesContext, "/test"));
+        root = facesContext.getViewRoot();
+        vdl.buildView(facesContext, root,"if2.xhtml");
+        c = root.findComponent("form");
+        Assert.assertNull("form is not null", c);
+        // start and end are from if2.xhtml, so they shouldn't be here!
+        c = root.findComponent("start");
+        Assert.assertNotNull("start is null", c);
+        c = root.findComponent("end");
+        Assert.assertNotNull("end is null", c);
+        facesContext.getAttributes().remove(root);
+
+    }
+    
+    @Test
+    public void testIf2() throws Exception
+    {
+        Map session = facesContext.getExternalContext().getSessionMap();
+        Employee e = new Employee();
+        session.put("employee", e);
+
+        UIViewRoot root = facesContext.getViewRoot();
+
+        // make sure the form is there
+        e.setManagement(false);
+        vdl.buildView(facesContext, root,"if2.xhtml");
+        UIComponent c = root.findComponent("form");
+        Assert.assertNull("form is not null", c);
+        c = root.findComponent("start");
+        Assert.assertNotNull("start is null", c);
+        c = root.findComponent("end");
+        Assert.assertNotNull("end is null", c);
+        //facesContext.getAttributes().remove(root);
+        
+        //rebuild if.xml but with form present now
+        e.setManagement(true);
+        root = facesContext.getViewRoot();
+        vdl.buildView(facesContext, root,"if2.xhtml");
+        c = root.findComponent("form");
+        Assert.assertNotNull("form is null", c);
+        // start and end shouldn't be in the component tree
+        c = root.findComponent("start");
+        Assert.assertNotNull("start is null", c);
+        c = root.findComponent("end");
+        Assert.assertNotNull("start is null", c);
+    }    
+    
+    @Test
+    public void testIf3() throws Exception
+    {
+        Map session = facesContext.getExternalContext().getSessionMap();
+        Employee e = new Employee();
+        session.put("employee", e);
+
+        UIViewRoot root = facesContext.getViewRoot();
+
+        // make sure the form is there
+        e.setManagement(true);
+        vdl.buildView(facesContext, root,"if3.xhtml");
+        UIComponent c = root.findComponent("form");
+        Assert.assertNotNull("form is null", c);
+        Assert.assertNotNull(c.getFacet("header"));
+        c = root.findComponent("start");
+        Assert.assertNotNull("start is null", c);
+        c = root.findComponent("end");
+        Assert.assertNotNull("end is null", c);
+        //facesContext.getAttributes().remove(root);
+        
+        //rebuild if.xml but with form present now
+        e.setManagement(false);
+        root = facesContext.getViewRoot();
+        vdl.buildView(facesContext, root,"if3.xhtml");
+        c = root.findComponent("form");
+        Assert.assertNotNull("form is null", c);
+        Assert.assertNull(c.getFacet("header"));
+        // start and end shouldn't be in the component tree
+        c = root.findComponent("start");
+        Assert.assertNotNull("start is null", c);
+        c = root.findComponent("end");
+        Assert.assertNotNull("start is null", c);
+    }
+}

Added: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jstl/core/if2.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jstl/core/if2.xhtml?rev=991417&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jstl/core/if2.xhtml
(added)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jstl/core/if2.xhtml
Wed Sep  1 01:55:20 2010
@@ -0,0 +1,35 @@
+<!--
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ $Id: if.xml 884721 2009-11-26 23:31:11Z lu4242 $
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:ui="http://java.sun.com/jsf/facelets"
+      xmlns:h="http://java.sun.com/jsf/html"
+      xmlns:c="http://java.sun.com/jsp/jstl/core">
+<body>
+
+<ui:composition>
+<h:outputText id="start" value="Start"/>
+<c:if test="#{employee.management}">
+	<h:form id="form">
+		<h:commandButton id="button" action="test" rendered="#{true}"/>
+	</h:form>
+</c:if>
+<h:outputText id="end" value="End"/>
+</ui:composition>
+
+
+</body>
+</html>

Added: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jstl/core/if3.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jstl/core/if3.xhtml?rev=991417&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jstl/core/if3.xhtml
(added)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jstl/core/if3.xhtml
Wed Sep  1 01:55:20 2010
@@ -0,0 +1,39 @@
+<!--
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ $Id: if.xml 884721 2009-11-26 23:31:11Z lu4242 $
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:ui="http://java.sun.com/jsf/facelets"
+      xmlns:h="http://java.sun.com/jsf/html"
+      xmlns:f="http://java.sun.com/jsf/core"
+      xmlns:c="http://java.sun.com/jsp/jstl/core">
+<body>
+
+<ui:composition>
+<h:outputText id="start" value="Start"/>
+<h:form id="form">
+    <f:facet name="header">
+       <c:if test="#{employee.management}">
+	     <h:commandButton id="button1" action="test" rendered="#{true}"/>
+         <h:commandButton id="button2" action="test" rendered="#{true}"/>
+       </c:if>
+    </f:facet>
+</h:form>
+<h:outputText id="end" value="End"/>
+</ui:composition>
+
+
+</body>
+</html>



Mime
View raw message