Author: abelevich
Date: 2009-08-21 10:24:03 -0400 (Fri, 21 Aug 2009)
New Revision: 15252
Modified:
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/facelets/tag/AjaxHandler.java
Log:
fix limitRender
Modified:
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
===================================================================
---
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2009-08-21
14:22:29 UTC (rev 15251)
+++
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2009-08-21
14:24:03 UTC (rev 15252)
@@ -5,22 +5,24 @@
import javax.faces.component.behavior.FacesBehavior;
import javax.faces.context.FacesContext;
+import org.ajax4jsf.component.AjaxClientBehavior;
+
/**
* @author Anton Belevich
*
*/
@FacesBehavior(value="org.ajax4jsf.behavior.Ajax")
-public class AjaxBehavior extends javax.faces.component.behavior.AjaxBehavior {
+public class AjaxBehavior extends javax.faces.component.behavior.AjaxBehavior implements
AjaxClientBehavior{
public static final String BEHAVIOR_ID = "org.ajax4jsf.behavior.Ajax";
public static final String LIMIT_RENDER = "limitRender";
- private boolean limitRender;
+ private Boolean limitRender;
public boolean isLimitRender() {
- if(this.limitRender) {
- return this.limitRender;
+ if(this.limitRender != null) {
+ return this.limitRender.booleanValue();
}
ValueExpression ex = getValueExpression(LIMIT_RENDER);
@@ -30,7 +32,7 @@
return value != null ? value.booleanValue() : false;
}
- return this.limitRender;
+ return false;
}
@@ -56,7 +58,7 @@
values = new Object[] { superState };
}
} else {
- values = new Object[1];
+ values = new Object[2];
values[0] = superState;
values[1] = limitRender;
}
@@ -65,6 +67,26 @@
}
@Override
+ public void setValueExpression(String name, ValueExpression expression) {
+ if(expression != null && expression.isLiteralText()) {
+ if(LIMIT_RENDER.equals(name)) {
+ Object value = getExpressionLiteralValue(expression);
+ this.limitRender = value != null ? (Boolean)value : Boolean.FALSE ;
+ }
+ }
+ super.setValueExpression(name, expression);
+ }
+
+ protected Object getExpressionLiteralValue(ValueExpression expression) {
+ Object value = null;
+ if(expression != null) {
+ ELContext elContext = FacesContext.getCurrentInstance().getELContext();
+ value = expression.getValue(elContext);
+ }
+ return value;
+ }
+
+ @Override
public void restoreState(FacesContext context, Object state) {
if (state != null) {
@@ -77,4 +99,4 @@
}
}
}
-}
+}
\ No newline at end of file
Modified:
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/facelets/tag/AjaxHandler.java
===================================================================
---
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/facelets/tag/AjaxHandler.java 2009-08-21
14:22:29 UTC (rev 15251)
+++
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/facelets/tag/AjaxHandler.java 2009-08-21
14:24:03 UTC (rev 15252)
@@ -1,7 +1,10 @@
package org.ajax4jsf.facelets.tag;
+import java.beans.BeanDescriptor;
+import java.beans.BeanInfo;
import java.io.IOException;
import java.util.Collection;
+import java.util.List;
import javax.el.ELContext;
import javax.el.MethodExpression;
@@ -12,8 +15,11 @@
import javax.faces.event.AbortProcessingException;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.event.AjaxBehaviorListener;
+import javax.faces.view.AttachedObjectTarget;
import javax.faces.view.BehaviorHolderAttachedObjectHandler;
+import javax.faces.view.BehaviorHolderAttachedObjectTarget;
import javax.faces.view.facelets.BehaviorConfig;
+import javax.faces.view.facelets.ComponentHandler;
import javax.faces.view.facelets.CompositeFaceletHandler;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.TagAttribute;
@@ -22,11 +28,9 @@
import org.ajax4jsf.component.behavior.AjaxBehavior;
-/**
- * @author Anton Belevich
- *
- */
+import com.sun.faces.facelets.tag.jsf.CompositeComponentTagHandler;
+
public class AjaxHandler extends TagHandler implements
BehaviorHolderAttachedObjectHandler {
private final TagAttribute event;
@@ -38,6 +42,8 @@
private final TagAttribute immediate;
private final TagAttribute listener;
private final TagAttribute limitRender;
+ private final boolean wrapping;
+
public AjaxHandler(BehaviorConfig config) {
super(config);
@@ -50,23 +56,85 @@
this.immediate = this.getAttribute("immediate");
this.listener = this.getAttribute("listener");
this.limitRender = this.getAttribute("limitRender");
+ this.wrapping = isWrapping();
}
public void apply(FaceletContext fContext, UIComponent parent) throws IOException {
String eventName = getEventName();
- if(!isWrapping()) {
- applyAttachedObject(fContext, parent, eventName);
+ if(this.wrapping) {
+ nextHandler.apply(fContext, parent);
} else {
- this.nextHandler.apply(fContext, parent);
+ applyNested(fContext, parent, eventName);
}
}
+ private void applyNested(FaceletContext ctx, UIComponent parent, String eventName) {
+
+ if (!ComponentHandler.isNew(parent)) {
+ return;
+ }
+
+ if (UIComponent.isCompositeComponent(parent)) {
+
+ BeanInfo componentBeanInfo = (BeanInfo)
parent.getAttributes().get(UIComponent.BEANINFO_KEY);
+ if (null == componentBeanInfo) {
+ throw new TagException(tag, "Error: enclosing composite component does not have
BeanInfo attribute");
+ }
+ BeanDescriptor componentDescriptor = componentBeanInfo.getBeanDescriptor();
+ if (null == componentDescriptor) {
+ throw new TagException(tag, "Error: enclosing composite component BeanInfo does
not have BeanDescriptor");
+ }
+
+ List<AttachedObjectTarget> targetList = (List<AttachedObjectTarget>)
componentDescriptor.getValue(AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY);
+
+ if (null == targetList) {
+ throw new TagException(tag, "Error: enclosing composite component does not
support behavior events");
+ }
+
+ boolean supportedEvent = false;
+ for (AttachedObjectTarget target : targetList) {
+ if (target instanceof BehaviorHolderAttachedObjectTarget) {
+ BehaviorHolderAttachedObjectTarget behaviorTarget =
(BehaviorHolderAttachedObjectTarget) target;
+ if ((null != eventName && eventName.equals(behaviorTarget.getName()))
+ || (null == eventName && behaviorTarget.isDefaultEvent())) {
+ supportedEvent = true;
+ break;
+ }
+ }
+ }
+
+ if (supportedEvent) {
+ CompositeComponentTagHandler.getAttachedObjectHandlers(parent).add(this);
+ } else {
+ throw new TagException(tag, "Error: enclosing composite component does not
support event " + eventName);
+ }
+
+ } else if (parent instanceof ClientBehaviorHolder) {
+ applyAttachedObject(ctx, parent, eventName);
+ } else {
+ throw new TagException(this.tag,"Unable to attach <f:ajax> to
non-ClientBehaviorHolder parent");
+ }
+ }
+
+
+// private void applyWrapping(FaceletContext ctx, UIComponent parent, String eventName)
throws IOException {
+// AjaxBehavior ajaxBehavior = createAjaxBehavior(ctx, eventName);
+//
+// FacesContext context = ctx.getFacesContext();
+// AjaxBehaviors ajaxBehaviors = AjaxBehaviors.getAjaxBehaviors(context, true);
+// ajaxBehaviors.pushBehavior(context, ajaxBehavior, eventName);
+//
+// nextHandler.apply(ctx, parent);
+//
+// ajaxBehaviors.popBehavior();
+// }
+
public void applyAttachedObject(FaceletContext fContext, UIComponent parent, String
eventName) {
ClientBehaviorHolder bHolder = (ClientBehaviorHolder) parent;
if (null == eventName) {
eventName = bHolder.getDefaultEventName();
if (null == eventName) {
- throw new TagException(this.tag, "Event attribute could not be determined:
" + eventName);
+ throw new TagException(this.tag, "Event attribute could not be determined:
" + eventName);
}
} else {
Collection<String> eventNames = bHolder.getEventNames();
@@ -74,12 +142,12 @@
throw new TagException(this.tag, eventName + "event is not supported for
the " + parent.getClass().getSimpleName());
}
}
- AjaxBehavior ajaxBehavior = createBehavior(fContext, parent, eventName);
+ AjaxBehavior ajaxBehavior = createAjaxBehavior(fContext, eventName);
bHolder.addClientBehavior(eventName, ajaxBehavior);
}
- public AjaxBehavior createBehavior(FaceletContext fContext, UIComponent parent, String
eventName) {
+ public AjaxBehavior createAjaxBehavior(FaceletContext fContext, String eventName) {
Application application = fContext.getFacesContext().getApplication();
AjaxBehavior ajaxBehavior =
(AjaxBehavior)application.createBehavior(AjaxBehavior.BEHAVIOR_ID);