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 2013/09/25 17:02:22 UTC
svn commit: r1526200 - in /myfaces/core/trunk/impl/src:
main/java/org/apache/myfaces/view/facelets/
main/java/org/apache/myfaces/view/facelets/impl/
main/java/org/apache/myfaces/view/facelets/tag/composite/
main/java/org/apache/myfaces/view/facelets/ta...
Author: lu4242
Date: Wed Sep 25 15:02:21 2013
New Revision: 1526200
URL: http://svn.apache.org/r1526200
Log:
MYFACES-3733 Implement vdl.createComponent(...) (Solve the refresh problem (allow c:if work in programmatic added sections).)
Added:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DynamicComponentRefreshTransientBuildEvent.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletDynamicComponentRefreshTransientBuildEvent.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguageBase.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/PublishDynamicComponentRefreshTransientBuildCallback.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleCCVDL7.java
- copied, changed from r1525868, myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleCCVDL4.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/ComponentBindingVDLBean7.java
- copied, changed from r1525868, myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/ComponentBindingVDLBean4.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/CustomSessionBean.java
myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleCCVDL7.xhtml
- copied, changed from r1525868, myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleCCVDL4.xhtml
myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/componentBindingVDL_7.xhtml
- copied, changed from r1525868, myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/componentBindingVDL_4.xhtml
myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/resources/testComposite/dynComp_7.xhtml
- copied, changed from r1525868, myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/resources/testComposite/dynComp_4.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/FaceletViewDeclarationLanguage.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/composite/CreateDynamicCompositeComponentListener.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
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ChooseHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ForEachHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/IfHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/DecorateHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/IncludeHandler.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DynamicComponentRefreshTransientBuildEvent.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DynamicComponentRefreshTransientBuildEvent.java?rev=1526200&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DynamicComponentRefreshTransientBuildEvent.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DynamicComponentRefreshTransientBuildEvent.java Wed Sep 25 15:02:21 2013
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.ComponentSystemEvent;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+public class DynamicComponentRefreshTransientBuildEvent extends ComponentSystemEvent
+{
+ public static final String DYN_COMP_REFRESH_FLAG = "oam.vf.DYN_COMP_REFRESH_FLAG";
+
+ public DynamicComponentRefreshTransientBuildEvent(UIComponent component)
+ {
+ super(component);
+ }
+
+ public void setComponent(UIComponent newComponent)
+ {
+ super.source = newComponent;
+ }
+}
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=1526200&r1=1526199&r2=1526200&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 25 15:02:21 2013
@@ -21,10 +21,12 @@ package org.apache.myfaces.view.facelets
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import javax.faces.FactoryFinder;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.component.UniqueIdVendor;
+import javax.faces.component.visit.VisitContextFactory;
import javax.faces.context.FacesContext;
import javax.faces.view.AttachedObjectHandler;
import javax.faces.view.EditableValueHolderAttachedObjectHandler;
@@ -663,4 +665,21 @@ abstract public class FaceletComposition
public void setDynamicComponentTopLevel(boolean value)
{
}
+
+ /**
+ * Indicate if the current facelet section is a dynamic component section,
+ * which means it was added to the component tree using vdl.createComponent(...);
+ *
+ * @since 2.2
+ * @return
+ */
+ public boolean isDynamicComponentSection()
+ {
+ return false;
+ }
+
+ public VisitContextFactory getVisitContextFactory()
+ {
+ return (VisitContextFactory)FactoryFinder.getFactory(FactoryFinder.VISIT_CONTEXT_FACTORY);
+ }
}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletDynamicComponentRefreshTransientBuildEvent.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletDynamicComponentRefreshTransientBuildEvent.java?rev=1526200&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletDynamicComponentRefreshTransientBuildEvent.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletDynamicComponentRefreshTransientBuildEvent.java Wed Sep 25 15:02:21 2013
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.ComponentSystemEvent;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+public class FaceletDynamicComponentRefreshTransientBuildEvent extends ComponentSystemEvent
+{
+ public static final String DYNAMIC_COMPONENT_BINDING_NEEDS_REFRESH = "oam.vf.DCB_NEEDS_REFRESH";
+
+ public FaceletDynamicComponentRefreshTransientBuildEvent(UIComponent component)
+ {
+ super(component);
+ }
+
+ public void setComponent(UIComponent newComponent)
+ {
+ super.source = newComponent;
+ }
+
+}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java?rev=1526200&r1=1526199&r2=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java Wed Sep 25 15:02:21 2013
@@ -28,6 +28,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -56,6 +57,8 @@ import javax.faces.component.UINamingCon
import javax.faces.component.UIPanel;
import javax.faces.component.UIViewParameter;
import javax.faces.component.UIViewRoot;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitHint;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
@@ -102,7 +105,6 @@ import org.apache.myfaces.shared.config.
import org.apache.myfaces.shared.util.ClassUtils;
import org.apache.myfaces.shared.util.StringUtils;
import org.apache.myfaces.shared.util.WebConfigParamUtils;
-import org.apache.myfaces.shared.view.ViewDeclarationLanguageBase;
import org.apache.myfaces.view.ViewDeclarationLanguageStrategy;
import org.apache.myfaces.view.ViewMetadataBase;
import org.apache.myfaces.view.facelets.FaceletViewHandler.NullWriter;
@@ -156,7 +158,7 @@ import org.apache.myfaces.view.facelets.
*
* @since 2.0
*/
-public class FaceletViewDeclarationLanguage extends ViewDeclarationLanguageBase
+public class FaceletViewDeclarationLanguage extends FaceletViewDeclarationLanguageBase
{
//private static final Log log = LogFactory.getLog(FaceletViewDeclarationLanguage.class);
private static final Logger log = Logger.getLogger(FaceletViewDeclarationLanguage.class.getName());
@@ -287,6 +289,9 @@ public class FaceletViewDeclarationLangu
private final static int STATE_KEY_LEN = STATE_KEY.length();
+ private static final Set<VisitHint> VISIT_HINTS_DYN_REFRESH = Collections.unmodifiableSet(
+ EnumSet.of(VisitHint.SKIP_ITERATION));
+
/**
* Key used to cache component ids for the counter
*/
@@ -366,7 +371,15 @@ public class FaceletViewDeclarationLangu
{
if (isFilledView(context, view))
{
- return;
+ if (view != null &&
+ FaceletViewDeclarationLanguageBase.isDynamicComponentRefreshTransientBuildActive(context, view))
+ {
+ // don't return
+ }
+ else
+ {
+ return;
+ }
}
// setup our viewId
@@ -445,7 +458,12 @@ public class FaceletViewDeclarationLangu
if (refreshTransientBuild)
{
//context.setProcessingEvents(true);
-
+ if (FaceletViewDeclarationLanguageBase.isDynamicComponentRefreshTransientBuildActive(context))
+ {
+ VisitContext visitContext = (VisitContext) getVisitContextFactory().
+ getVisitContext(context, null, VISIT_HINTS_DYN_REFRESH);
+ view.visitTree(visitContext, new PublishDynamicComponentRefreshTransientBuildCallback());
+ }
if (!usePartialStateSavingOnThisView || refreshTransientBuildOnPSS)
{
// When the facelet is applied, all components are removed and added from view,
@@ -2792,6 +2810,8 @@ public class FaceletViewDeclarationLangu
}
// Create a temporal component base class where all components will be put, but we are only
// interested in the inner UIComponent and if multiple are created, return this one.
+ boolean requiresDynamicRefresh = false;
+ boolean requiresFaceletDynamicRefresh = false;
UIPanel tempParent
= (UIPanel) context.getApplication().createComponent(
context, UIPanel.COMPONENT_TYPE, null);
@@ -2808,6 +2828,24 @@ public class FaceletViewDeclarationLangu
finally
{
tempParent.popComponentFromEL(context);
+ // There are two cases:
+ // 1. If we are under facelets algorithm control (binding case), the refreshing logic will be done
+ // outside this block. We can check that condition easily with FaceletCompositionContext
+ // 2. If we are not under facelets algorithm control, check if the dynamic component requires refresh,
+ // if that so, mark the view to be refreshed and reset the flag, otherwise continue. This check
+ // allows us to decide if we add a third listener to refresh on transient build.
+ // Check if the current component requires dynamic refresh and if that so,
+ FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(context);
+ if (fcc != null)
+ {
+ requiresFaceletDynamicRefresh = true;
+ }
+ else if (FaceletViewDeclarationLanguageBase.isDynamicComponentNeedsRefresh(context))
+ {
+ FaceletViewDeclarationLanguageBase.activateDynamicComponentRefreshTransientBuild(context);
+ FaceletViewDeclarationLanguageBase.resetDynamicComponentNeedsRefreshFlag(context);
+ requiresDynamicRefresh = true;
+ }
}
if (tempParent.getChildCount() > 1)
{
@@ -2817,11 +2855,15 @@ public class FaceletViewDeclarationLangu
tempParent.getAttributes().put("oam.vf.DYN_WRAPPER", baseKey);
tempParent.subscribeToEvent(PostRestoreStateEvent.class, new
RefreshDynamicComponentListener(taglibURI, tagName, attributes, baseKey));
+ if (requiresFaceletDynamicRefresh)
+ {
+ FaceletViewDeclarationLanguageBase.dynamicComponentNeedsRefresh(context);
+ }
}
else if (tempParent.getChildCount() == 1)
{
createdComponent = tempParent.getChildren().get(0);
-
+ boolean requiresRefresh = false;
// One child. In that case there are three choices:
if (UIComponent.isCompositeComponent(createdComponent))
{
@@ -2837,8 +2879,11 @@ public class FaceletViewDeclarationLangu
createdComponent.getAttributes().put(ComponentSupport.MARK_CREATED, null);
createdComponent.subscribeToEvent(PostAddToViewEvent.class, new
CreateDynamicCompositeComponentListener(taglibURI, tagName, attributes, baseKey));
- createdComponent.subscribeToEvent(PostRestoreStateEvent.class, new
- RefreshDynamicComponentListener(taglibURI, tagName, attributes, baseKey));
+ requiresRefresh = true;
+ if (requiresFaceletDynamicRefresh)
+ {
+ FaceletViewDeclarationLanguageBase.dynamicComponentNeedsRefresh(context);
+ }
}
else if (createdComponent.getChildCount() > 0)
{
@@ -2849,18 +2894,20 @@ public class FaceletViewDeclarationLangu
createdComponent.getAttributes().put("oam.vf.GEN_MARK_ID",
createdComponent.getAttributes().get(ComponentSupport.MARK_CREATED));
createdComponent.getAttributes().put(ComponentSupport.MARK_CREATED, null);
- createdComponent.subscribeToEvent(PostRestoreStateEvent.class, new
- RefreshDynamicComponentListener(taglibURI, tagName, attributes, baseKey));
+ requiresRefresh = true;
+ if (requiresFaceletDynamicRefresh)
+ {
+ FaceletViewDeclarationLanguageBase.dynamicComponentNeedsRefresh(context);
+ }
}
else if (createdComponent.isTransient())
{
// Just transient markup inside. It is necessary to wrap
// that content into a component. Requires refresh. No need to
- // save MARK_CREATED.
+ // save MARK_CREATED. No requires dynamic refresh.
createdComponent = tempParent;
tempParent.getAttributes().put("oam.vf.DYN_WRAPPER", baseKey);
- createdComponent.subscribeToEvent(PostRestoreStateEvent.class, new
- RefreshDynamicComponentListener(taglibURI, tagName, attributes, baseKey));
+ requiresRefresh = true;
}
else
{
@@ -2871,6 +2918,23 @@ public class FaceletViewDeclarationLangu
// added component.
createdComponent.getAttributes().put(ComponentSupport.MARK_CREATED, null);
}
+ if (requiresRefresh)
+ {
+ createdComponent.subscribeToEvent(PostRestoreStateEvent.class, new
+ RefreshDynamicComponentListener(taglibURI, tagName, attributes, baseKey));
+ }
+ if (requiresDynamicRefresh)
+ {
+ createdComponent.subscribeToEvent(DynamicComponentRefreshTransientBuildEvent.class, new
+ RefreshDynamicComponentListener(taglibURI, tagName, attributes, baseKey));
+ createdComponent.getAttributes().put(
+ DynamicComponentRefreshTransientBuildEvent.DYN_COMP_REFRESH_FLAG, Boolean.TRUE);
+ }
+ if (requiresFaceletDynamicRefresh)
+ {
+ createdComponent.subscribeToEvent(FaceletDynamicComponentRefreshTransientBuildEvent.class, new
+ RefreshDynamicComponentListener(taglibURI, tagName, attributes, baseKey));
+ }
}
}
catch (IOException e)
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguageBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguageBase.java?rev=1526200&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguageBase.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguageBase.java Wed Sep 25 15:02:21 2013
@@ -0,0 +1,91 @@
+/*
+ * 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;
+
+import javax.faces.FactoryFinder;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.visit.VisitContextFactory;
+import javax.faces.context.FacesContext;
+import org.apache.myfaces.shared.view.ViewDeclarationLanguageBase;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+public abstract class FaceletViewDeclarationLanguageBase extends ViewDeclarationLanguageBase
+{
+ /**
+ * UIViewRoot attribute to check if the dynamic components in a view should be refreshed under a transient build
+ */
+ private static final String DYNAMIC_COMPONENT_REFRESH_TRANSIENT_BUILD = "oam.vf.DCRTB";
+
+ private static final String DYNAMIC_COMPONENT_NEEDS_REFRESH = "oam.vf.DC_NEEDS_REFRESH";
+
+ private VisitContextFactory _visitContextFactory = null;
+
+ protected VisitContextFactory getVisitContextFactory()
+ {
+ if (_visitContextFactory == null)
+ {
+ _visitContextFactory = (VisitContextFactory)FactoryFinder.getFactory(FactoryFinder.VISIT_CONTEXT_FACTORY);
+ }
+ return _visitContextFactory;
+ }
+
+ public static boolean isDynamicComponentRefreshTransientBuildActive(FacesContext facesContext)
+ {
+ if (facesContext.getViewRoot() == null)
+ {
+ return false;
+ }
+ return Boolean.TRUE.equals(facesContext.getViewRoot().getAttributes().get(
+ DYNAMIC_COMPONENT_REFRESH_TRANSIENT_BUILD));
+ }
+
+ public static boolean isDynamicComponentRefreshTransientBuildActive(FacesContext facesContext, UIViewRoot view)
+ {
+ return Boolean.TRUE.equals(view.getAttributes().get(
+ DYNAMIC_COMPONENT_REFRESH_TRANSIENT_BUILD));
+ }
+
+ public static void activateDynamicComponentRefreshTransientBuild(FacesContext facesContext)
+ {
+ if (!isDynamicComponentRefreshTransientBuildActive(facesContext))
+ {
+ facesContext.getViewRoot().getAttributes().put(
+ DYNAMIC_COMPONENT_REFRESH_TRANSIENT_BUILD, Boolean.TRUE);
+ }
+ }
+
+ public static boolean isDynamicComponentNeedsRefresh(FacesContext context)
+ {
+ return Boolean.TRUE.equals(context.getAttributes().get(DYNAMIC_COMPONENT_NEEDS_REFRESH));
+ }
+
+ public static void dynamicComponentNeedsRefresh(FacesContext context)
+ {
+ context.getAttributes().put(DYNAMIC_COMPONENT_NEEDS_REFRESH, Boolean.TRUE);
+ }
+
+ public static void resetDynamicComponentNeedsRefreshFlag(FacesContext context)
+ {
+ context.getAttributes().put(DYNAMIC_COMPONENT_NEEDS_REFRESH, Boolean.FALSE);
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/PublishDynamicComponentRefreshTransientBuildCallback.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/PublishDynamicComponentRefreshTransientBuildCallback.java?rev=1526200&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/PublishDynamicComponentRefreshTransientBuildCallback.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/PublishDynamicComponentRefreshTransientBuildCallback.java Wed Sep 25 15:02:21 2013
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitResult;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+public class PublishDynamicComponentRefreshTransientBuildCallback implements VisitCallback
+{
+ public VisitResult visit(VisitContext context, UIComponent target)
+ {
+ if (target.getAttributes().containsKey(DynamicComponentRefreshTransientBuildEvent.DYN_COMP_REFRESH_FLAG))
+ {
+ context.getFacesContext().getApplication().publishEvent(
+ context.getFacesContext(), DynamicComponentRefreshTransientBuildEvent.class,
+ target.getClass(), target);
+ }
+ return VisitResult.ACCEPT;
+ }
+
+}
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=1526200&r1=1526199&r2=1526200&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 25 15:02:21 2013
@@ -24,10 +24,12 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import javax.faces.FactoryFinder;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.component.UniqueIdVendor;
+import javax.faces.component.visit.VisitContextFactory;
import javax.faces.context.FacesContext;
import javax.faces.view.AttachedObjectHandler;
import javax.faces.view.EditableValueHolderAttachedObjectHandler;
@@ -152,6 +154,11 @@ public class FaceletCompositionContextIm
private boolean _dynamicComponentHandler;
private boolean _oldRefreshingTransientBuild;
private boolean _dynamicComponentTopLevel;
+ private int _dynamicComponentSection = 0;
+
+ private List<Integer> _dynamicOldDeletionLevel;
+
+ private VisitContextFactory _visitContextFactory = null;
public FaceletCompositionContextImpl(FaceletFactory factory, FacesContext facesContext)
{
@@ -209,6 +216,7 @@ public class FaceletCompositionContextIm
_sectionUniqueNormalIdCounter = _sectionUniqueIdCounter;
_sectionUniqueComponentNormalIdCounter = _sectionUniqueComponentIdCounter;
_dynamicComponentTopLevel = true;
+ _dynamicComponentSection = 1;
}
@@ -277,6 +285,8 @@ public class FaceletCompositionContextIm
_sectionUniqueComponentNormalIdCounter = null;
_sectionUniqueComponentMetadataIdCounter = null;
_sharedStringBuilder = null;
+ _visitContextFactory = null;
+ _dynamicOldDeletionLevel = null;
}
@Override
@@ -1136,11 +1146,30 @@ public class FaceletCompositionContextIm
_sectionUniqueNormalIdCounter = _sectionUniqueIdCounter;
_sectionUniqueComponentNormalIdCounter = _sectionUniqueComponentIdCounter;
_dynamicComponentTopLevel = true;
+ _dynamicComponentSection++;
+ if (_dynamicOldDeletionLevel == null)
+ {
+ _dynamicOldDeletionLevel = new ArrayList<Integer>(4);
+ }
+ _dynamicOldDeletionLevel.add(_deletionLevel);
+ // Increase one level in the mark/delete algorithm to avoid any interference in the previous code.
+ increaseComponentLevelMarkedForDeletion();
+
}
@Override
public void popDynamicComponentSection()
{
+ decreaseComponentLevelMarkedForDeletion();
+ int oldDeletionLevel = _dynamicOldDeletionLevel.remove(_dynamicOldDeletionLevel.size()-1);
+ if (_deletionLevel != oldDeletionLevel)
+ {
+ // This happens because in a dynamic component section, the dynamic top component level does not take
+ // part in the algorithm. The easiest solution so far is just decrease one level to let it as it was
+ // before enter the algorithm.
+ decreaseComponentLevelMarkedForDeletion();
+ }
+
_sectionUniqueIdCounter = _sectionUniqueIdCounterStack.remove(
_sectionUniqueIdCounterStack.size()-1);
_sectionUniqueComponentIdCounter = _sectionUniqueComponentIdCounterStack.remove(
@@ -1155,18 +1184,48 @@ public class FaceletCompositionContextIm
_sectionUniqueNormalIdCounter = _sectionUniqueIdCounter;
_sectionUniqueComponentNormalIdCounter = _sectionUniqueComponentIdCounter;
_dynamicComponentTopLevel = false;
+ _dynamicComponentSection--;
}
+ @Override
public boolean isDynamicComponentTopLevel()
{
return _dynamicComponentTopLevel;
}
+ @Override
public void setDynamicComponentTopLevel(boolean value)
{
_dynamicComponentTopLevel = value;
}
+ @Override
+ public boolean isDynamicComponentSection()
+ {
+ return _dynamicComponentSection > 0;
+ }
+
+ @Override
+ public VisitContextFactory getVisitContextFactory()
+ {
+ if (_visitContextFactory == null)
+ {
+ // Store it in application map improve performance because it avoids FactoryFinde.getFactory(...) call
+ // which has synchronized blocks.
+ _visitContextFactory = (VisitContextFactory) _facesContext.getExternalContext().
+ getApplicationMap().get("oam.vf.VisitContextFactory");
+ if (_visitContextFactory == null)
+ {
+ VisitContextFactory factory = (VisitContextFactory)
+ FactoryFinder.getFactory(FactoryFinder.VISIT_CONTEXT_FACTORY);
+ _facesContext.getExternalContext().
+ getApplicationMap().put("oam.vf.VisitContextFactory", factory);
+ _visitContextFactory = factory;
+ }
+ }
+ return _visitContextFactory;
+ }
+
private static class KeyEntryIterator<K, V> implements Iterator<K>
{
private Iterator<Map.Entry<K, V>> _delegateIterator;
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CreateDynamicCompositeComponentListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CreateDynamicCompositeComponentListener.java?rev=1526200&r1=1526199&r2=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CreateDynamicCompositeComponentListener.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CreateDynamicCompositeComponentListener.java Wed Sep 25 15:02:21 2013
@@ -28,8 +28,13 @@ import javax.faces.event.ComponentSystem
import javax.faces.event.ComponentSystemEventListener;
import javax.faces.view.facelets.Facelet;
import org.apache.myfaces.view.facelets.AbstractFacelet;
+import org.apache.myfaces.view.facelets.DynamicComponentRefreshTransientBuildEvent;
+import org.apache.myfaces.view.facelets.FaceletCompositionContext;
+import org.apache.myfaces.view.facelets.FaceletDynamicComponentRefreshTransientBuildEvent;
import org.apache.myfaces.view.facelets.FaceletFactory;
import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
+import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguageBase;
+import org.apache.myfaces.view.facelets.compiler.RefreshDynamicComponentListener;
import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
/**
@@ -141,6 +146,26 @@ public class CreateDynamicCompositeCompo
component.getAttributes().put(ComponentSupport.MARK_CREATED, null);
}
}
+
+ if (FaceletViewDeclarationLanguageBase.isDynamicComponentNeedsRefresh(facesContext))
+ {
+ FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(facesContext);
+ if (fcc == null)
+ {
+ FaceletViewDeclarationLanguageBase.activateDynamicComponentRefreshTransientBuild(facesContext);
+ FaceletViewDeclarationLanguageBase.resetDynamicComponentNeedsRefreshFlag(facesContext);
+ component.subscribeToEvent(DynamicComponentRefreshTransientBuildEvent.class, new
+ RefreshDynamicComponentListener(taglibURI, tagName, attributes, baseKey));
+ component.getAttributes().put(
+ DynamicComponentRefreshTransientBuildEvent.DYN_COMP_REFRESH_FLAG, Boolean.TRUE);
+
+ }
+ else
+ {
+ component.subscribeToEvent(FaceletDynamicComponentRefreshTransientBuildEvent.class, new
+ RefreshDynamicComponentListener(taglibURI, tagName, attributes, baseKey));
+ }
+ }
}
finally
{
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=1526200&r1=1526199&r2=1526200&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 25 15:02:21 2013
@@ -43,6 +43,7 @@ import org.apache.myfaces.view.facelets.
import org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy;
import org.apache.myfaces.view.facelets.FaceletCompositionContext;
import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
+import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguageBase;
/**
*
@@ -631,6 +632,11 @@ public final class ComponentSupport
}
}
+ public static void markComponentToRefreshDynamically(FacesContext context, UIComponent component)
+ {
+ FaceletViewDeclarationLanguageBase.dynamicComponentNeedsRefresh(context);
+ }
+
public static UIComponent findComponentChildOrFacetFrom(FacesContext facesContext, UIComponent parent, String expr)
{
final char separatorChar = UINamingContainer.getSeparatorChar(facesContext);
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=1526200&r1=1526199&r2=1526200&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 25 15:02:21 2013
@@ -19,9 +19,12 @@
package org.apache.myfaces.view.facelets.tag.jsf;
import java.io.IOException;
+import java.util.Collections;
+import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -35,6 +38,10 @@ import javax.faces.component.UIComponent
import javax.faces.component.UniqueIdVendor;
import javax.faces.component.ValueHolder;
import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitHint;
+import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
import javax.faces.validator.BeanValidator;
import javax.faces.validator.Validator;
@@ -53,6 +60,9 @@ import org.apache.myfaces.view.facelets.
import org.apache.myfaces.view.facelets.ComponentState;
import org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy;
import org.apache.myfaces.view.facelets.FaceletCompositionContext;
+import org.apache.myfaces.view.facelets.FaceletDynamicComponentRefreshTransientBuildEvent;
+import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
+import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguageBase;
import org.apache.myfaces.view.facelets.tag.MetaRulesetImpl;
import org.apache.myfaces.view.facelets.tag.jsf.core.AjaxHandler;
import org.apache.myfaces.view.facelets.tag.jsf.core.FacetHandler;
@@ -70,6 +80,9 @@ import org.apache.myfaces.view.facelets.
public class ComponentTagHandlerDelegate extends TagHandlerDelegate
{
private final static Logger log = Logger.getLogger(ComponentTagHandlerDelegate.class.getName());
+
+ private static final Set<VisitHint> VISIT_HINTS_DYN_REFRESH = Collections.unmodifiableSet(
+ EnumSet.of(VisitHint.SKIP_ITERATION));
private final ComponentHandler _delegate;
@@ -225,6 +238,16 @@ public class ComponentTagHandlerDelegate
if (c != null)
{
componentFound = true;
+ // Check if the binding needs dynamic refresh and if that so, invoke the refresh from this location, to
+ // preserve the same context
+ if (_delegate.getBinding() != null &&
+ c.getAttributes().containsKey(
+ FaceletDynamicComponentRefreshTransientBuildEvent.DYNAMIC_COMPONENT_BINDING_NEEDS_REFRESH))
+ {
+ VisitContext visitContext = (VisitContext) mctx.getVisitContextFactory().
+ getVisitContext(facesContext, null, VISIT_HINTS_DYN_REFRESH);
+ c.visitTree(visitContext, new PublishFaceletDynamicComponentRefreshTransientBuildCallback());
+ }
mctx.incrementUniqueComponentId();
@@ -486,6 +509,29 @@ public class ComponentTagHandlerDelegate
// and this ensures stability of the generated ids.
c.getAttributes().put(DefaultFaceletsStateManagementStrategy.COMPONENT_ADDED_AFTER_BUILD_VIEW,
ComponentState.REMOVE_ADD);
+
+ if (FaceletViewDeclarationLanguageBase.isDynamicComponentNeedsRefresh(ctx.getFacesContext()))
+ {
+ FaceletViewDeclarationLanguageBase.resetDynamicComponentNeedsRefreshFlag(
+ ctx.getFacesContext());
+ FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);
+ if (mctx.isUsingPSSOnThisView())
+ {
+ FaceletViewDeclarationLanguage.cleanTransientBuildOnRestore(faces);
+ }
+ else
+ {
+ FaceletViewDeclarationLanguageBase.activateDynamicComponentRefreshTransientBuild(faces);
+ }
+ //
+ // Mark top binding component to be dynamically refreshed. In that way, facelets algorithm
+ // will be able to decide if the component children requires to be refreshed dynamically
+ // or not.
+ c.getAttributes().put(
+ FaceletDynamicComponentRefreshTransientBuildEvent.
+ DYNAMIC_COMPONENT_BINDING_NEEDS_REFRESH,
+ Boolean.TRUE);
+ }
}
}
}
@@ -864,4 +910,15 @@ public class ComponentTagHandlerDelegate
// By default, all default validators should be added
return true;
}
+
+ private static class PublishFaceletDynamicComponentRefreshTransientBuildCallback implements VisitCallback
+ {
+ public VisitResult visit(VisitContext context, UIComponent target)
+ {
+ context.getFacesContext().getApplication().publishEvent(
+ context.getFacesContext(), FaceletDynamicComponentRefreshTransientBuildEvent.class,
+ target.getClass(), target);
+ return VisitResult.ACCEPT;
+ }
+ }
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ChooseHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ChooseHandler.java?rev=1526200&r1=1526199&r2=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ChooseHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ChooseHandler.java Wed Sep 25 15:02:21 2013
@@ -206,6 +206,10 @@ public final class ChooseHandler extends
//Mark the parent component to be saved and restored fully.
ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent);
}
+ if (fcc.isDynamicComponentSection())
+ {
+ ComponentSupport.markComponentToRefreshDynamically(ctx.getFacesContext(), parent);
+ }
}
private Integer getSavedOption(FaceletContext ctx, FaceletCompositionContext fcc,
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ForEachHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ForEachHandler.java?rev=1526200&r1=1526199&r2=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ForEachHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/ForEachHandler.java Wed Sep 25 15:02:21 2013
@@ -317,6 +317,10 @@ public final class ForEachHandler extend
//Mark the parent component to be saved and restored fully.
ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent);
}
+ if (fcc.isDynamicComponentSection())
+ {
+ ComponentSupport.markComponentToRefreshDynamically(ctx.getFacesContext(), parent);
+ }
}
private final ValueExpression capture(String name, PageContext pctx)
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/IfHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/IfHandler.java?rev=1526200&r1=1526199&r2=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/IfHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/IfHandler.java Wed Sep 25 15:02:21 2013
@@ -152,5 +152,9 @@ public final class IfHandler extends Tag
//Mark the parent component to be saved and restored fully.
ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent);
}
+ if (fcc.isDynamicComponentSection())
+ {
+ ComponentSupport.markComponentToRefreshDynamically(ctx.getFacesContext(), parent);
+ }
}
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/DecorateHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/DecorateHandler.java?rev=1526200&r1=1526199&r2=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/DecorateHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/DecorateHandler.java Wed Sep 25 15:02:21 2013
@@ -236,6 +236,10 @@ public final class DecorateHandler exten
//Mark the parent component to be saved and restored fully.
ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent);
}
+ if (!_template.isLiteral() && fcc.isDynamicComponentSection())
+ {
+ ComponentSupport.markComponentToRefreshDynamically(ctx.getFacesContext(), parent);
+ }
}
public boolean apply(FaceletContext ctx, UIComponent parent, String name) throws IOException, FacesException,
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/IncludeHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/IncludeHandler.java?rev=1526200&r1=1526199&r2=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/IncludeHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/IncludeHandler.java Wed Sep 25 15:02:21 2013
@@ -259,5 +259,9 @@ public final class IncludeHandler extend
//Mark the parent component to be saved and restored fully.
ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent);
}
+ if (!src.isLiteral() && fcc.isDynamicComponentSection())
+ {
+ ComponentSupport.markComponentToRefreshDynamically(ctx.getFacesContext(), parent);
+ }
}
}
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java?rev=1526200&r1=1526199&r2=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/AcidMyFacesRequestTestCase.java Wed Sep 25 15:02:21 2013
@@ -30,6 +30,7 @@ import org.apache.myfaces.mc.test.core.A
import org.apache.myfaces.shared.config.MyfacesConfig;
import org.apache.myfaces.test.mock.MockPrintWriter;
import org.apache.myfaces.view.facelets.pss.acid.managed.CheckActionEventBean;
+import org.apache.myfaces.view.facelets.pss.acid.managed.CustomSessionBean;
import org.apache.myfaces.view.facelets.pss.acid.managed.ResourceDependencyBean;
import org.junit.Assert;
import org.junit.Test;
@@ -994,6 +995,74 @@ public class AcidMyFacesRequestTestCase
tearDownRequest();
}
+
+ @Test
+ public void testAddSimpleCCVDL7() throws Exception
+ {
+ setupRequest("/addSimpleCCVDL7.xhtml");
+ processLifecycleExecuteAndRender();
+
+ UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
+ Assert.assertEquals(1, comp.getChildCount());
+ UIComponent wrapper = comp.getChildren().get(0);
+ Assert.assertNotNull(wrapper);
+ Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
+ UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
+ Assert.assertNotNull(ccContent);
+ Assert.assertEquals(3, ccContent.getChildCount());
+ //Assert.assertEquals("Dynamically added header",
+ // ccContent.getChildren().get(0).getFacet("header").getAttributes().get("value"));
+ Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
+ MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
+ String content1 = new String(writer1.content());
+ Assert.assertTrue(content1.contains("Dynamically added markup"));
+ int indexDynHeader1_1 = content1.indexOf("Start Dynamic Header");
+ int indexDynHeader1_2 = content1.indexOf("Dynamically added header", indexDynHeader1_1);
+ int indexDynHeader1_3 = content1.indexOf("End Dynamic Header", indexDynHeader1_2);
+ Assert.assertNotSame(-1, indexDynHeader1_1);
+ Assert.assertNotSame(-1, indexDynHeader1_2);
+ Assert.assertNotSame(-1, indexDynHeader1_3);
+
+ Assert.assertFalse(content1.contains("This is section 1"));
+
+ UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
+ submit(button);
+ processLifecycleExecute();
+
+ CustomSessionBean sessionBean = facesContext.getApplication().evaluateExpressionGet(
+ facesContext, "#{customSessionBean}", CustomSessionBean.class);
+ // Here we change the value to show the section 1 part. If the refresh algorithm works,
+ // this part should be rendered
+ sessionBean.setShowSection1(true);
+
+ processRender();
+
+ comp = facesContext.getViewRoot().findComponent("mainForm:component");
+ Assert.assertEquals(1, comp.getChildCount());
+ wrapper = comp.getChildren().get(0);
+ Assert.assertNotNull(wrapper);
+ Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
+ ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
+ Assert.assertNotNull(ccContent);
+ Assert.assertEquals(3, ccContent.getChildCount());
+ //Assert.assertEquals("Dynamically added header",
+ // ccContent.getChildren().get(0).getFacet("header").getAttributes().get("value"));
+ Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
+ MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
+ String content2 = new String(writer2.content());
+ Assert.assertTrue(content2.contains("Dynamically added markup"));
+ int indexDynHeader1 = content2.indexOf("Start Dynamic Header");
+ int indexDynHeader2 = content2.indexOf("Dynamically added header", indexDynHeader1);
+ int indexDynHeader3 = content2.indexOf("End Dynamic Header", indexDynHeader2);
+ Assert.assertNotSame(-1, indexDynHeader1);
+ Assert.assertNotSame(-1, indexDynHeader2);
+ Assert.assertNotSame(-1, indexDynHeader3);
+
+ Assert.assertTrue(content2.contains("This is section 1"));
+
+ tearDownRequest();
+ }
+
@Test
public void testComponentBindingVDL_1() throws Exception
@@ -1020,7 +1089,7 @@ public class AcidMyFacesRequestTestCase
UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
submit(button);
- processLifecycleExecuteAndRender();
+ processLifecycleExecute();
Assert.assertNotNull(comp);
Assert.assertEquals(2, comp.getChildCount());
@@ -1038,6 +1107,9 @@ public class AcidMyFacesRequestTestCase
Assert.assertEquals("Dynamically added header",
ccContent.getChildren().get(0).getFacet("header").getAttributes().get("value"));
Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
+
+ processRender();
+
MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
String content2 = new String(writer2.content());
Assert.assertTrue(content2.contains("Dynamically added markup"));
@@ -1558,4 +1630,115 @@ public class AcidMyFacesRequestTestCase
tearDownRequest();
}
+
+ @Test
+ public void testComponentBindingVDL_7() throws Exception
+ {
+ setupRequest("/componentBindingVDL_7.xhtml");
+ processLifecycleExecuteAndRender();
+
+ UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:panel");
+ Assert.assertNotNull(comp);
+ Assert.assertEquals(2, comp.getChildCount());
+
+ UIComponent wrapper = comp.getChildren().get(1);
+ Assert.assertNotNull(wrapper);
+ Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
+ UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
+ Assert.assertNotNull(ccContent);
+ Assert.assertEquals(3, ccContent.getChildCount());
+ //Assert.assertEquals("Dynamically added header",
+ // ccContent.getChildren().get(0).getFacet("header").getAttributes().get("value"));
+ Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
+ MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
+ String content1 = new String(writer1.content());
+ Assert.assertTrue(content1.contains("Dynamically added markup"));
+ int indexDynHeader1_1 = content1.indexOf("Start Dynamic Header");
+ int indexDynHeader1_2 = content1.indexOf("Dynamically added header", indexDynHeader1_1);
+ int indexDynHeader1_3 = content1.indexOf("End Dynamic Header", indexDynHeader1_2);
+ Assert.assertNotSame(-1, indexDynHeader1_1);
+ Assert.assertNotSame(-1, indexDynHeader1_2);
+ Assert.assertNotSame(-1, indexDynHeader1_3);
+
+ Assert.assertFalse(content1.contains("This is section 1"));
+
+ UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
+ submit(button);
+ processLifecycleExecute();
+
+ CustomSessionBean sessionBean = facesContext.getApplication().evaluateExpressionGet(
+ facesContext, "#{customSessionBean}", CustomSessionBean.class);
+ // Here we change the value to show the section 1 part. If the refresh algorithm works,
+ // this part should be rendered
+ sessionBean.setShowSection1(true);
+
+ processRender();
+ Assert.assertNotNull(comp);
+ Assert.assertEquals(2, comp.getChildCount());
+
+ comp = facesContext.getViewRoot().findComponent("mainForm:panel");
+
+ Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
+ Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
+
+ wrapper = comp.getChildren().get(1);
+ Assert.assertNotNull(wrapper);
+ Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
+ ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
+ Assert.assertNotNull(ccContent);
+ Assert.assertEquals(3, ccContent.getChildCount());
+ //Assert.assertEquals("Dynamically added header",
+ // ccContent.getChildren().get(0).getFacet("header").getAttributes().get("value"));
+ Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
+ MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
+ String content2 = new String(writer2.content());
+ Assert.assertTrue(content2.contains("Dynamically added markup"));
+ int indexDynHeader2_1 = content2.indexOf("Start Dynamic Header");
+ int indexDynHeader2_2 = content2.indexOf("Dynamically added header", indexDynHeader2_1);
+ int indexDynHeader2_3 = content2.indexOf("End Dynamic Header", indexDynHeader2_2);
+ Assert.assertNotSame(-1, indexDynHeader2_1);
+ Assert.assertNotSame(-1, indexDynHeader2_2);
+ Assert.assertNotSame(-1, indexDynHeader2_3);
+
+ Assert.assertTrue(content2.contains("This is section 1"));
+
+ button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
+ submit(button);
+ processLifecycleExecute();
+
+ sessionBean.setShowSection1(false);
+
+ processRender();
+ Assert.assertNotNull(comp);
+ Assert.assertEquals(2, comp.getChildCount());
+
+ comp = facesContext.getViewRoot().findComponent("mainForm:panel");
+
+ Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
+ Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
+
+ wrapper = comp.getChildren().get(1);
+ Assert.assertNotNull(wrapper);
+ Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
+ ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
+ Assert.assertNotNull(ccContent);
+ Assert.assertEquals(3, ccContent.getChildCount());
+ //Assert.assertEquals("Dynamically added header",
+ // ccContent.getChildren().get(0).getFacet("header").getAttributes().get("value"));
+ Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
+ MockPrintWriter writer3 = (MockPrintWriter) response.getWriter();
+ String content3 = new String(writer3.content());
+ Assert.assertTrue(content3.contains("Dynamically added markup"));
+ int indexDynHeader3_1 = content3.indexOf("Start Dynamic Header");
+ int indexDynHeader3_2 = content3.indexOf("Dynamically added header", indexDynHeader3_1);
+ int indexDynHeader3_3 = content3.indexOf("End Dynamic Header", indexDynHeader3_2);
+ Assert.assertNotSame(-1, indexDynHeader3_1);
+ Assert.assertNotSame(-1, indexDynHeader3_2);
+ Assert.assertNotSame(-1, indexDynHeader3_3);
+
+ Assert.assertFalse(content3.contains("This is section 1"));
+
+ tearDownRequest();
+ }
+
}
Copied: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleCCVDL7.java (from r1525868, myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleCCVDL4.java)
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleCCVDL7.java?p2=myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleCCVDL7.java&p1=myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleCCVDL4.java&r1=1525868&r2=1526200&rev=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleCCVDL4.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/component/UIAddSimpleCCVDL7.java Wed Sep 25 15:02:21 2013
@@ -32,9 +32,9 @@ import javax.faces.event.SystemEvent;
import javax.faces.event.SystemEventListener;
import javax.faces.view.ViewDeclarationLanguage;
-@FacesComponent(value = "com.myapp.UIAddSimpleCCVDL4", createTag=true,
- namespace="http://testcomponent", tagName="addSimpleCCVDL4")
-public class UIAddSimpleCCVDL4 extends UIComponentBase implements
+@FacesComponent(value = "com.myapp.UIAddSimpleCCVDL7", createTag=true,
+ namespace="http://testcomponent", tagName="addSimpleCCVDL7")
+public class UIAddSimpleCCVDL7 extends UIComponentBase implements
SystemEventListener
{
@@ -42,7 +42,7 @@ public class UIAddSimpleCCVDL4 extends U
// Constructor
//
- public UIAddSimpleCCVDL4()
+ public UIAddSimpleCCVDL7()
{
setRendererType(null);
@@ -83,7 +83,7 @@ public class UIAddSimpleCCVDL4 extends U
Map<String, Object> attributes = new HashMap<String, Object>();
UIComponent component = vdl.createComponent(facesContext,
"http://java.sun.com/jsf/composite/testComposite",
- "dynComp_4", attributes);
+ "dynComp_7", attributes);
UIOutput text = (UIOutput) facesContext.getApplication().
createComponent(UIOutput.COMPONENT_TYPE);
text.setValue("Dynamically added header");
Copied: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/ComponentBindingVDLBean7.java (from r1525868, myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/ComponentBindingVDLBean4.java)
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/ComponentBindingVDLBean7.java?p2=myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/ComponentBindingVDLBean7.java&p1=myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/ComponentBindingVDLBean4.java&r1=1525868&r2=1526200&rev=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/ComponentBindingVDLBean4.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/ComponentBindingVDLBean7.java Wed Sep 25 15:02:21 2013
@@ -33,9 +33,9 @@ import javax.faces.view.ViewDeclarationL
*
* @author Leonardo Uribe
*/
-@ManagedBean(name="componentBindingVDLBean4")
+@ManagedBean(name="componentBindingVDLBean7")
@RequestScoped
-public class ComponentBindingVDLBean4
+public class ComponentBindingVDLBean7
{
private UIPanel panel;
@@ -65,7 +65,7 @@ public class ComponentBindingVDLBean4
Map<String, Object> attributes = new HashMap<String, Object>();
UIComponent cc = vdl.createComponent(facesContext,
"http://java.sun.com/jsf/composite/testComposite",
- "dynComp_4", attributes);
+ "dynComp_7", attributes);
UIOutput text = (UIOutput) facesContext.getApplication().
createComponent(UIOutput.COMPONENT_TYPE);
text.setValue("Dynamically added header");
Added: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/CustomSessionBean.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/CustomSessionBean.java?rev=1526200&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/CustomSessionBean.java (added)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/pss/acid/managed/CustomSessionBean.java Wed Sep 25 15:02:21 2013
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * 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.
+ */
+package org.apache.myfaces.view.facelets.pss.acid.managed;
+
+import java.io.Serializable;
+import javax.annotation.PostConstruct;
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.SessionScoped;
+
+/**
+ *
+ * @author lu4242
+ */
+@ManagedBean(name="customSessionBean")
+@SessionScoped
+public class CustomSessionBean implements Serializable
+{
+
+ private boolean showSection1;
+
+ @PostConstruct
+ public void init()
+ {
+ showSection1 = false;
+ }
+
+ /**
+ * @return the showSection1
+ */
+ public boolean isShowSection1()
+ {
+ return showSection1;
+ }
+
+ /**
+ * @param showSection1 the showSection1 to set
+ */
+ public void setShowSection1(boolean showSection1)
+ {
+ this.showSection1 = showSection1;
+ }
+
+}
Copied: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleCCVDL7.xhtml (from r1525868, myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleCCVDL4.xhtml)
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleCCVDL7.xhtml?p2=myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleCCVDL7.xhtml&p1=myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleCCVDL4.xhtml&r1=1525868&r2=1526200&rev=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleCCVDL4.xhtml (original)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/addSimpleCCVDL7.xhtml Wed Sep 25 15:02:21 2013
@@ -30,7 +30,7 @@
<h:form id="mainForm">
- <test:addSimpleCCVDL4 id="component"/>
+ <test:addSimpleCCVDL7 id="component"/>
<br/>
<h:commandButton id="postback" value="POSTback" action="#{testManagedBean.save}"/>
Copied: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/componentBindingVDL_7.xhtml (from r1525868, myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/componentBindingVDL_4.xhtml)
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/componentBindingVDL_7.xhtml?p2=myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/componentBindingVDL_7.xhtml&p1=myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/componentBindingVDL_4.xhtml&r1=1525868&r2=1526200&rev=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/componentBindingVDL_4.xhtml (original)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/componentBindingVDL_7.xhtml Wed Sep 25 15:02:21 2013
@@ -20,7 +20,7 @@
</h:head>
<h:body>
<h:form id="mainForm">
- <h:panelGroup id="panel" binding="#{componentBindingVDLBean4.panel}"/>
+ <h:panelGroup id="panel" binding="#{componentBindingVDLBean7.panel}"/>
<h:commandButton id="postback" value="POSTBACK"/>
</h:form>
</h:body>
Copied: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/resources/testComposite/dynComp_7.xhtml (from r1525868, myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/resources/testComposite/dynComp_4.xhtml)
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/resources/testComposite/dynComp_7.xhtml?p2=myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/resources/testComposite/dynComp_7.xhtml&p1=myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/resources/testComposite/dynComp_4.xhtml&r1=1525868&r2=1526200&rev=1526200&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/resources/testComposite/dynComp_4.xhtml (original)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/pss/acid/resources/testComposite/dynComp_7.xhtml Wed Sep 25 15:02:21 2013
@@ -4,11 +4,12 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:cc="http://java.sun.com/jsf/composite">
+ xmlns:cc="http://java.sun.com/jsf/composite"
+ xmlns:c="http://java.sun.com/jsp/jstl/core">
<cc:interface>
</cc:interface>
<cc:implementation>
- <h:panelGrid>
+ <h:panelGrid columns="1">
<f:facet name="header">
<h:panelGroup>
<p>Start Dynamic Header</p>
@@ -16,6 +17,11 @@
<h:outputText value=" End Dynamic Header "/>
</h:panelGroup>
</f:facet>
+ <h:panelGroup>
+ <c:if test="#{customSessionBean.showSection1}">
+ <p> This is section <h:outputText value="1"/> </p>
+ </c:if>
+ </h:panelGroup>
</h:panelGrid>
Dynamically added markup
<h:outputText value="Dynamically added child"/>