Author: nbelaevski
Date: 2009-08-18 09:51:52 -0400 (Tue, 18 Aug 2009)
New Revision: 15200
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java
Log:
Behaviors support added to PartialViewContextImpl
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java 2009-08-18
13:13:17 UTC (rev 15199)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java 2009-08-18
13:51:52 UTC (rev 15200)
@@ -26,9 +26,12 @@
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Set;
+import java.util.Map;
import javax.faces.component.UIComponent;
+import javax.faces.component.behavior.AjaxBehavior;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
import javax.faces.component.visit.VisitHint;
@@ -48,7 +51,9 @@
*/
public class PartialViewContextImpl extends PartialViewContextWrapper {
- private final PartialViewContext wrappedContext;
+ public static final String BEHAVIOR_EVENT_PARAMETER =
"javax.faces.behavior.event";
+
+ private final PartialViewContext wrappedContext;
private final String activatorId;
@@ -56,6 +61,8 @@
private boolean executeAll = true;
+ private String behaviorEvent = null;
+
public PartialViewContextImpl(PartialViewContext wrappedContext, String activatorId) {
super();
@@ -75,9 +82,9 @@
);
}
- private static class ComponentCallback implements VisitCallback {
+ private abstract static class ComponentCallback implements VisitCallback {
- private final String attributeName;
+ private final String behaviorEvent;
private boolean handleAll;
@@ -85,10 +92,10 @@
private Collection<String> componentIds = new LinkedHashSet<String>();
- public ComponentCallback(String attributeName, boolean handleNone,
+ public ComponentCallback(String behaviorEvent, boolean handleNone,
boolean handleAll) {
super();
- this.attributeName = attributeName;
+ this.behaviorEvent = behaviorEvent;
this.handleNone = handleNone;
this.handleAll = handleAll;
}
@@ -96,10 +103,55 @@
protected void addDefaultComponents(Collection<String> ids) {
}
+
+ private AjaxBehavior findBehavior(UIComponent target) {
+ AjaxBehavior result = null;
+ if (behaviorEvent != null) {
+ if (target instanceof ClientBehaviorHolder) {
+ ClientBehaviorHolder behaviorHolder = (ClientBehaviorHolder) target;
+ List<ClientBehavior> behaviors =
behaviorHolder.getClientBehaviors().get(behaviorEvent);
+ if (behaviors != null) {
+ for (ClientBehavior behavior : behaviors) {
+ if (behavior instanceof AjaxBehavior) {
+ AjaxBehavior ajaxBehavior = (AjaxBehavior) behavior;
+ if (!ajaxBehavior.isDisabled()) {
+ result = (AjaxBehavior) behavior;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (result == null) {
+ //TODO: log
+ }
+
+ return result;
+ }
+ protected Object getAttributeObject(UIComponent target) {
+ Object result = null;
+ if (behaviorEvent != null) {
+ AjaxBehavior ajaxBehavior = findBehavior(target);
+ if (ajaxBehavior != null) {
+ result = getBehaviorAttributeValue(ajaxBehavior);
+ }
+ } else {
+ result = getAttributeValue(target);
+ }
+
+ return result;
+ }
+
+ protected abstract Object getBehaviorAttributeValue(AjaxBehavior behavior);
+
+ protected abstract Object getAttributeValue(UIComponent component);
+
public VisitResult visit(VisitContext context, UIComponent target) {
- Object attributeValue = target.getAttributes().get(attributeName);
- Set<String> attributeIds = AjaxRendererUtils.asSet(attributeValue);
+ Object attributeObject = getAttributeObject(target);
+ Collection<String> attributeIds = AjaxRendererUtils.asSet(attributeObject);
if (attributeIds != null && !attributeIds.isEmpty()) {
if (attributeIds.contains(AjaxRendererUtils.ALL)) {
if (!AjaxRendererUtils.ALL_SET.equals(attributeIds)) {
@@ -144,8 +196,8 @@
private static class ExecuteComponentCallback extends ComponentCallback {
- public ExecuteComponentCallback() {
- super("execute", false, true);
+ public ExecuteComponentCallback(String behaviorEvent) {
+ super(behaviorEvent, false, true);
}
@Override
@@ -154,12 +206,21 @@
ids.add(AjaxRendererUtils.THIS);
}
+ @Override
+ public Object getAttributeValue(UIComponent component) {
+ return component.getAttributes().get("execute");
+ }
+
+ @Override
+ protected Object getBehaviorAttributeValue(AjaxBehavior behavior) {
+ return behavior.getExecute();
+ }
}
private static class RenderComponentCallback extends ComponentCallback {
- public RenderComponentCallback() {
- super("render", false, false);
+ public RenderComponentCallback(String behaviorEvent) {
+ super(behaviorEvent, false, false);
}
private boolean limitToList = false;
@@ -175,6 +236,16 @@
return visitResult;
}
+
+ @Override
+ public Object getAttributeValue(UIComponent component) {
+ return component.getAttributes().get("render");
+ }
+
+ @Override
+ protected Object getBehaviorAttributeValue(AjaxBehavior behavior) {
+ return behavior.getRender();
+ }
}
//TODO: data table support
@@ -189,13 +260,20 @@
return ids;
}
+ private void decodeBehaviorEvent(FacesContext context) {
+ Map<String, String> requestParameterMap =
context.getExternalContext().getRequestParameterMap();
+ this.behaviorEvent = requestParameterMap.get(BEHAVIOR_EVENT_PARAMETER);
+ }
+
private void processExecute(PartialViewContext partialViewContext) {
if (!hasProcessedExecute) {
hasProcessedExecute = true;
FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ decodeBehaviorEvent(facesContext);
- ExecuteComponentCallback executeCallback = new ExecuteComponentCallback();
+ ExecuteComponentCallback executeCallback = new
ExecuteComponentCallback(behaviorEvent);
boolean visitResult = facesContext.getViewRoot().visitTree(
createVisitContext(facesContext),
@@ -222,7 +300,7 @@
FacesContext facesContext = FacesContext.getCurrentInstance();
if (!partialViewContext.isRenderAll()) {
- RenderComponentCallback renderCallback = new RenderComponentCallback();
+ RenderComponentCallback renderCallback = new RenderComponentCallback(behaviorEvent);
boolean visitResult = facesContext.getViewRoot().visitTree(
createVisitContext(facesContext),
renderCallback);
Show replies by date