Author: nbelaevski
Date: 2010-11-04 20:09:58 -0400 (Thu, 04 Nov 2010)
New Revision: 19944
Modified:
trunk/core/impl/src/main/java/org/richfaces/context/ComponentCallback.java
trunk/core/impl/src/main/java/org/richfaces/context/ExecuteComponentCallback.java
trunk/core/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java
trunk/core/impl/src/main/java/org/richfaces/context/RenderComponentCallback.java
Log:
https://jira.jboss.org/browse/RF-9342
https://jira.jboss.org/browse/RF-9428
Modified: trunk/core/impl/src/main/java/org/richfaces/context/ComponentCallback.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/context/ComponentCallback.java 2010-11-04
21:35:17 UTC (rev 19943)
+++ trunk/core/impl/src/main/java/org/richfaces/context/ComponentCallback.java 2010-11-05
00:09:58 UTC (rev 19944)
@@ -43,22 +43,17 @@
*/
abstract class ComponentCallback implements VisitCallback {
- private Collection<String> componentIds = new LinkedHashSet<String>();
+ protected final FacesContext facesContext;
private final String behaviorEvent;
- private final String defaultIdAttribute;
- ComponentCallback(String behaviorEvent, String defaultIdAttribute) {
+ ComponentCallback(FacesContext facesContext, String behaviorEvent) {
super();
+ this.facesContext = facesContext;
this.behaviorEvent = behaviorEvent;
- this.defaultIdAttribute = defaultIdAttribute;
}
- protected String getDefaultComponentId() {
- return null;
- }
-
private AjaxClientBehavior findBehavior(UIComponent target) {
if ((behaviorEvent == null) || !(target instanceof ClientBehaviorHolder)) {
return null;
@@ -82,32 +77,22 @@
return null;
}
- protected abstract Object getBehaviorAttributeValue(AjaxClientBehavior behavior);
-
- protected abstract Object getAttributeValue(UIComponent component);
-
- protected void doVisit(FacesContext context, UIComponent target, AjaxClientBehavior
behavior) {
- Object attributeObject;
-
- if (behavior == null) {
- attributeObject = getAttributeValue(target);
- } else {
- attributeObject = getBehaviorAttributeValue(behavior);
- }
-
+ protected Collection<String> resolveComponents(Object value, UIComponent
target, String defaultValue) {
//TODO - unit tests check for "@none" element
- Collection<String> attributeIds =
CoreAjaxRendererUtils.asIdsSet(attributeObject);
- if (attributeIds == null) {
- attributeIds = new LinkedHashSet<String>();
+ Collection<String> ids = CoreAjaxRendererUtils.asIdsSet(value);
+ if (ids == null) {
+ ids = new LinkedHashSet<String>(1);
}
- if (attributeIds.isEmpty() && defaultIdAttribute != null) {
+ if (ids.isEmpty() && defaultValue != null) {
// asSet() returns copy of original set and we're free to modify it
- attributeIds.add(defaultIdAttribute);
+ ids.add(defaultValue);
}
- componentIds.addAll(CoreRendererUtils.INSTANCE.findComponentsFor(context, target,
attributeIds));
+ return CoreRendererUtils.INSTANCE.findComponentsFor(facesContext, target, ids);
}
+
+ protected abstract void doVisit(UIComponent target, AjaxClientBehavior behavior);
public final VisitResult visit(VisitContext visitContext, UIComponent target) {
AjaxClientBehavior ajaxBehavior = null;
@@ -116,13 +101,9 @@
ajaxBehavior = findBehavior(target);
}
- doVisit(visitContext.getFacesContext(), target, ajaxBehavior);
+ doVisit(target, ajaxBehavior);
return VisitResult.COMPLETE;
}
- public Collection<String> getComponentIds() {
- return componentIds;
- }
-
}
Modified:
trunk/core/impl/src/main/java/org/richfaces/context/ExecuteComponentCallback.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/context/ExecuteComponentCallback.java 2010-11-04
21:35:17 UTC (rev 19943)
+++
trunk/core/impl/src/main/java/org/richfaces/context/ExecuteComponentCallback.java 2010-11-05
00:09:58 UTC (rev 19944)
@@ -21,7 +21,11 @@
package org.richfaces.context;
+import java.util.Collection;
+import java.util.Collections;
+
import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
import org.ajax4jsf.component.AjaxClientBehavior;
import org.richfaces.component.AjaxContainer;
@@ -30,19 +34,30 @@
* @author akolonitsky
* @since Oct 13, 2009
*/
-class ExecuteComponentCallback extends ComponentCallback {
+class ExecuteComponentCallback extends RenderComponentCallback {
- ExecuteComponentCallback(String behaviorEvent) {
- super(behaviorEvent, AjaxContainer.META_CLIENT_ID);
+ private Collection<String> executeIds = null;
+
+ ExecuteComponentCallback(FacesContext facesContext, String behaviorEvent) {
+ super(facesContext, behaviorEvent);
}
@Override
- public Object getAttributeValue(UIComponent component) {
- return component.getAttributes().get("execute");
+ protected void doVisit(UIComponent target, AjaxClientBehavior behavior) {
+ super.doVisit(target, behavior);
+
+ Object value;
+ if (behavior != null) {
+ value = behavior.getExecute();
+ } else {
+ value = target.getAttributes().get("execute");
+ }
+
+ executeIds = resolveComponents(value, target, AjaxContainer.META_CLIENT_ID);
}
-
- @Override
- protected Object getBehaviorAttributeValue(AjaxClientBehavior behavior) {
- return behavior.getExecute();
+
+ public Collection<String> getExecuteIds() {
+ return (executeIds != null) ? executeIds : Collections.<String>emptySet();
}
+
}
Modified: trunk/core/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java 2010-11-04
21:35:17 UTC (rev 19943)
+++
trunk/core/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java 2010-11-05
00:09:58 UTC (rev 19944)
@@ -71,8 +71,11 @@
private FacesContext facesContext;
private Collection<String> executeIds = null;
+
private Collection<String> renderIds = null;
+ private Collection<String> componentRenderIds = null;
+
private Boolean renderAll = null;
private String activatorComponentId = null;
@@ -84,6 +87,12 @@
private PartialViewContext wrappedViewContext;
+ private String onbeforedomupdate;
+
+ private String oncomplete;
+
+ private Object responseData;
+
public PartialViewContextImpl(PartialViewContext wrappedViewContext, FacesContext
facesContext) {
super();
@@ -98,7 +107,7 @@
if (detectContextMode() == ContextMode.DIRECT) {
if (executeIds == null) {
executeIds = new LinkedHashSet<String>();
- setupExecuteIds(executeIds);
+ visitActivatorAtExecute();
}
return executeIds;
@@ -237,7 +246,7 @@
PartialViewContext pvc = facesContext.getPartialViewContext();
UIViewRoot viewRoot = facesContext.getViewRoot();
Collection<String> phaseIds = pvc.getRenderIds();
- setupRenderIds(phaseIds);
+ visitActivatorAtRender(phaseIds);
try {
PartialResponseWriter writer = pvc.getPartialResponseWriter();
@@ -285,14 +294,28 @@
}
}
- private void setupExecuteIds(Collection<String> ids) {
- ExecuteComponentCallback callback = new ExecuteComponentCallback(behaviorEvent);
+ private void setupExecuteCallbackData(ExecuteComponentCallback callback) {
+ executeIds.addAll(callback.getExecuteIds());
- if (visitActivatorComponent(activatorComponentId, callback)) {
- ids.addAll(callback.getComponentIds());
+ setupRenderCallbackData(callback);
+ }
+
+ private void setupRenderCallbackData(RenderComponentCallback callback) {
+ componentRenderIds = callback.getRenderIds();
+ onbeforedomupdate = callback.getOnbeforedomupdate();
+ oncomplete = callback.getOncomplete();
+ responseData = callback.getData();
+ limitRender = callback.isLimitRender();
+ }
+
+ private void visitActivatorAtExecute() {
+ ExecuteComponentCallback callback = new ExecuteComponentCallback(facesContext,
behaviorEvent);
- if (!ids.contains(ALL)) {
- addImplicitExecuteIds(ids);
+ if (visitActivatorComponent(activatorComponentId, callback,
EnumSet.of(VisitHint.SKIP_UNRENDERED))) {
+ setupExecuteCallbackData(callback);
+
+ if (!executeIds.contains(ALL)) {
+ addImplicitExecuteIds(executeIds);
}
} else {
//TODO - log or exception?
@@ -300,26 +323,30 @@
}
}
- private void setupRenderIds(Collection<String> ids) {
+ private void visitActivatorAtRender(Collection<String> ids) {
if (!isRenderAll()) {
- RenderComponentCallback callback = new
RenderComponentCallback(behaviorEvent);
+ RenderComponentCallback callback = new RenderComponentCallback(facesContext,
behaviorEvent);
- if (visitActivatorComponent(activatorComponentId, callback)) {
- ids.addAll(callback.getComponentIds());
- limitRender = callback.isLimitRender();
-
- if (!Boolean.TRUE.equals(renderAll) && !ids.contains(ALL)) {
- addImplicitRenderIds(ids, limitRender);
-
- //TODO - review
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance();
- ajaxContext.setOnbeforedomupdate(callback.getOnbeforedomupdate());
- ajaxContext.appendOncomplete(callback.getOncomplete());
- ajaxContext.setResponseData(callback.getData());
- }
+ if (visitActivatorComponent(activatorComponentId, callback,
EnumSet.noneOf(VisitHint.class))) {
+ setupRenderCallbackData(callback);
} else {
//TODO - the same as for "execute"
}
+
+ //take collection value stored during execute
+ if (componentRenderIds != null) {
+ ids.addAll(componentRenderIds);
+ }
+
+ if (!Boolean.TRUE.equals(renderAll) && !ids.contains(ALL)) {
+ addImplicitRenderIds(ids, limitRender);
+
+ //TODO - review
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance();
+ ajaxContext.setOnbeforedomupdate(onbeforedomupdate);
+ ajaxContext.appendOncomplete(oncomplete);
+ ajaxContext.setResponseData(responseData);
+ }
}
}
@@ -407,10 +434,9 @@
}
}
- private boolean visitActivatorComponent(String componentActivatorId, VisitCallback
visitCallback) {
+ private boolean visitActivatorComponent(String componentActivatorId, VisitCallback
visitCallback, Set<VisitHint> visitHints) {
Set<String> idsToVisit = Collections.singleton(componentActivatorId);
- Set<VisitHint> visitHints = EnumSet.of(VisitHint.SKIP_UNRENDERED);
VisitContext visitContext = new ExecuteExtendedVisitContext(facesContext,
idsToVisit, visitHints);
boolean visitResult = facesContext.getViewRoot().visitTree(visitContext,
visitCallback);
Modified:
trunk/core/impl/src/main/java/org/richfaces/context/RenderComponentCallback.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/context/RenderComponentCallback.java 2010-11-04
21:35:17 UTC (rev 19943)
+++
trunk/core/impl/src/main/java/org/richfaces/context/RenderComponentCallback.java 2010-11-05
00:09:58 UTC (rev 19944)
@@ -21,6 +21,9 @@
package org.richfaces.context;
+import java.util.Collection;
+import java.util.Collections;
+
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -33,6 +36,8 @@
*/
class RenderComponentCallback extends ComponentCallback {
+ private Collection<String> renderIds = null;
+
private boolean limitRender = false;
private String oncomplete;
@@ -41,8 +46,8 @@
private Object data;
- RenderComponentCallback(String behaviorEvent) {
- super(behaviorEvent, null);
+ RenderComponentCallback(FacesContext facesContext, String behaviorEvent) {
+ super(facesContext, behaviorEvent);
}
public boolean isLimitRender() {
@@ -61,31 +66,28 @@
return data;
}
+ public Collection<String> getRenderIds() {
+ return (renderIds != null) ? renderIds : Collections.<String>emptySet();
+ }
+
@Override
- protected void doVisit(FacesContext context, UIComponent target, AjaxClientBehavior
behavior) {
- super.doVisit(context, target, behavior);
-
- limitRender = CoreAjaxRendererUtils.isAjaxLimitRender(target);
- onbeforedomupdate = CoreAjaxRendererUtils.getAjaxOnBeforeDomUpdate(target);
- oncomplete = CoreAjaxRendererUtils.getAjaxOncomplete(target);
- data = CoreAjaxRendererUtils.getAjaxData(target);
-
+ protected void doVisit(UIComponent target, AjaxClientBehavior behavior) {
+ Object renderValue;
if (behavior != null) {
+ renderValue = behavior.getRender();
limitRender = behavior.isLimitRender();
onbeforedomupdate = behavior.getOnbeforedomupdate();
oncomplete = behavior.getOncomplete();
data = behavior.getData();
+ } else {
+ renderValue = target.getAttributes().get("render");
+ limitRender = CoreAjaxRendererUtils.isAjaxLimitRender(target);
+ onbeforedomupdate = CoreAjaxRendererUtils.getAjaxOnBeforeDomUpdate(target);
+ oncomplete = CoreAjaxRendererUtils.getAjaxOncomplete(target);
+ data = CoreAjaxRendererUtils.getAjaxData(target);
}
+
+ renderIds = resolveComponents(renderValue, target, null);
}
- @Override
- public Object getAttributeValue(UIComponent component) {
- return component.getAttributes().get("render");
- }
-
- @Override
- protected Object getBehaviorAttributeValue(AjaxClientBehavior behavior) {
- return behavior.getRender();
- }
-
}