Author: abelevich
Date: 2010-05-21 12:32:57 -0400 (Fri, 21 May 2010)
New Revision: 17183
Modified:
root/ui/core/trunk/api/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/AjaxHandler.java
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/BehaviorTagHandlerDelegate.java
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/CustomBehaviorHandler.java
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/tag/AjaxBehaviorRule.java
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/tag/BehaviorRule.java
Log:
use 'getMetaRules' method from CustomBehaviorHandler to retrieve specific for the
handler behavior rules, rename ajaxBehaviorListener -> listener
Modified:
root/ui/core/trunk/api/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2010-05-21
14:59:23 UTC (rev 17182)
+++
root/ui/core/trunk/api/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2010-05-21
16:32:57 UTC (rev 17183)
@@ -51,7 +51,7 @@
.of(ClientBehaviorHint.SUBMITTING));
enum PropertyKeys {
- data, execute, onbeforedomupdate, onbegin, oncomplete, onerror, onevent, queueId,
render, similarityGroupingId, status, disabled, limitRender, immediate, behaviorListener
+ data, execute, onbeforedomupdate, onbegin, oncomplete, onerror, onevent, queueId,
render, similarityGroupingId, status, disabled, limitRender, immediate
}
private static final Set<String> ALL_SINGLETON_SET =
Collections.singleton(AjaxRendererUtils.ALL);
@@ -150,7 +150,7 @@
@SuppressWarnings("unchecked")
public Collection<String> getExecute() {
Object executeObject = getStateHelper().eval(PropertyKeys.execute);
-
+
if (executeObject instanceof Collection<?>) {
return (Collection<String>) executeObject;
} else {
Modified:
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/AjaxHandler.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/AjaxHandler.java 2010-05-21
14:59:23 UTC (rev 17182)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/AjaxHandler.java 2010-05-21
16:32:57 UTC (rev 17183)
@@ -39,44 +39,46 @@
import javax.faces.view.facelets.BehaviorConfig;
import javax.faces.view.facelets.ComponentHandler;
import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
import javax.faces.view.facelets.TagException;
import org.ajax4jsf.component.behavior.AjaxBehavior;
import org.richfaces.component.AbstractAttachQueue;
import org.richfaces.view.facelets.html.BehaviorStack.BehaviorInfo;
+import org.richfaces.view.facelets.tag.AjaxBehaviorRule;
/**
* @author Anton Belevich
- *
+ *
*/
public class AjaxHandler extends CustomBehaviorHandler {
-
+
public AjaxHandler(BehaviorConfig config) {
- super(config);
+ super(config);
}
-
+
public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
-
+
Application application = ctx.getFacesContext().getApplication();
Behavior behavior = application.createBehavior(getBehaviorId());
- if(behavior instanceof AjaxBehavior) {
+ if (behavior instanceof AjaxBehavior) {
setAttributes(ctx, behavior);
- AjaxBehavior ajaxBehavior = (AjaxBehavior)behavior;
-
+ AjaxBehavior ajaxBehavior = (AjaxBehavior) behavior;
+
FacesContext context = ctx.getFacesContext();
BehaviorStack ajaxBehaviors = BehaviorStack.getBehaviorStack(context, true);
String eventName = getEventName();
ajaxBehaviors.pushBehavior(context, ajaxBehavior, AjaxBehavior.BEHAVIOR_ID,
eventName);
-
+
AttachQueueStack attachQueueStack = AttachQueueStack.getStack(context,
true);
AttachQueueInfo attachQueueInfo = new AttachQueueInfo(parent);
attachQueueStack.push(attachQueueInfo);
-
+
nextHandler.apply(ctx, parent);
-
+
attachQueueStack.pop();
-
+
BehaviorInfo behaviorInfo = ajaxBehaviors.popBehavior();
if (behaviorInfo != null) {
if (behaviorInfo.isWrapping()) {
@@ -97,17 +99,16 @@
if (attachQueue != null) {
attachQueue.associateWith(ajaxBehavior);
}
-
+
applyNested(ctx, parent, ajaxBehavior);
}
} else {
- //TODO nick - is this possible?
+ // TODO nick - is this possible?
}
-
+
}
}
-
-
+
private void applyNested(FaceletContext ctx, UIComponent parent, AjaxBehavior
behavior) {
if (!ComponentHandler.isNew(parent)) {
return;
@@ -125,13 +126,12 @@
if (null == componentDescriptor) {
throw new TagException(tag,
- "Error: enclosing composite component
BeanInfo does not have BeanDescriptor");
+ "Error: enclosing composite component BeanInfo does not have
BeanDescriptor");
}
- @SuppressWarnings(
- "unchecked") List<AttachedObjectTarget> targetList =
- (List<AttachedObjectTarget>) componentDescriptor.getValue(
- AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY);
+ @SuppressWarnings("unchecked")
+ 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");
@@ -144,7 +144,7 @@
BehaviorHolderAttachedObjectTarget behaviorTarget =
(BehaviorHolderAttachedObjectTarget) target;
if ((null != eventName &&
eventName.equals(behaviorTarget.getName()))
- || (null == eventName &&
behaviorTarget.isDefaultEvent())) {
+ || (null == eventName &&
behaviorTarget.isDefaultEvent())) {
supportedEvent = true;
break;
@@ -165,7 +165,7 @@
throw new TagException(this.tag, "Unable to attach <a4j:ajax> to
non-ClientBehaviorHolder parent");
}
}
-
+
private String resolveEventName(ClientBehaviorHolder bHolder) {
String eventName = getEventName();
if (null == eventName) {
@@ -178,13 +178,17 @@
Collection<String> eventNames = bHolder.getEventNames();
if (!eventNames.contains(eventName)) {
- throw new TagException(this.tag,
- eventName + "event is not supported for the
"
- + bHolder.getClass().getSimpleName());
+ throw new TagException(this.tag, eventName + "event is not supported
for the "
+ + bHolder.getClass().getSimpleName());
}
}
return eventName;
}
-
+
+ @Override
+ public MetaRule[] getMetaRules() {
+ return new MetaRule[] { AjaxBehaviorRule.INSTANCE };
+ }
+
}
Modified:
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/BehaviorTagHandlerDelegate.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/BehaviorTagHandlerDelegate.java 2010-05-21
14:59:23 UTC (rev 17182)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/BehaviorTagHandlerDelegate.java 2010-05-21
16:32:57 UTC (rev 17183)
@@ -30,12 +30,11 @@
import javax.faces.context.FacesContext;
import javax.faces.view.AttachedObjectHandler;
import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
import javax.faces.view.facelets.MetaRuleset;
import javax.faces.view.facelets.TagHandlerDelegate;
import org.ajax4jsf.component.behavior.ClientBehavior;
-import org.richfaces.view.facelets.tag.AjaxBehaviorRule;
-import org.richfaces.view.facelets.tag.BehaviorRule;
/**
* @author Anton Belevich
@@ -51,11 +50,14 @@
private String eventName;
+ private MetaRule[] metaRules;
+
public BehaviorTagHandlerDelegate(CustomBehaviorHandler owner, TagHandlerDelegate
wrappedHandlerDelegate) {
this.owner = owner;
this.wrappedHandlerDelegate = wrappedHandlerDelegate;
this.behaviorId = owner.getBehaviorId();
this.eventName = owner.getEventName();
+ this.metaRules = owner.getMetaRules();
}
@Override
@@ -88,8 +90,9 @@
public MetaRuleset createMetaRuleset(Class type) {
MetaRuleset metaRuleset = wrappedHandlerDelegate.createMetaRuleset(type);
- metaRuleset.addRule(BehaviorRule.INSTANCE);
- metaRuleset.addRule(AjaxBehaviorRule.INSTANCE);
+ for (MetaRule metaRule : metaRules) {
+ metaRuleset.addRule(metaRule);
+ }
return metaRuleset;
}
Modified:
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/CustomBehaviorHandler.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/CustomBehaviorHandler.java 2010-05-21
14:59:23 UTC (rev 17182)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/CustomBehaviorHandler.java 2010-05-21
16:32:57 UTC (rev 17183)
@@ -25,14 +25,17 @@
import javax.faces.view.facelets.BehaviorConfig;
import javax.faces.view.facelets.BehaviorHandler;
import javax.faces.view.facelets.CompositeFaceletHandler;
+import javax.faces.view.facelets.MetaRule;
import javax.faces.view.facelets.TagHandler;
import javax.faces.view.facelets.TagHandlerDelegate;
+import org.richfaces.view.facelets.tag.BehaviorRule;
+
/**
* @author Anton Belevich
*
*/
-public abstract class CustomBehaviorHandler extends BehaviorHandler {
+public class CustomBehaviorHandler extends BehaviorHandler {
TagHandlerDelegate helper;
@@ -41,13 +44,17 @@
}
public boolean isWrapping() {
- return ((this.nextHandler instanceof TagHandler) || (this.nextHandler instanceof
CompositeFaceletHandler));
+ return ((this.nextHandler instanceof TagHandler) || (this.nextHandler instanceof
CompositeFaceletHandler));
}
-
+
public boolean isWrappingAttachQueue() {
return (this.nextHandler instanceof AttachQueueHandler);
}
+ public MetaRule[] getMetaRules() {
+ return new MetaRule[] { BehaviorRule.INSTANCE };
+ }
+
@Override
protected TagHandlerDelegate getTagHandlerDelegate() {
if (helper == null) {
Modified:
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/tag/AjaxBehaviorRule.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/tag/AjaxBehaviorRule.java 2010-05-21
14:59:23 UTC (rev 17182)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/tag/AjaxBehaviorRule.java 2010-05-21
16:32:57 UTC (rev 17183)
@@ -24,7 +24,6 @@
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.view.facelets.FaceletContext;
-import javax.faces.view.facelets.MetaRule;
import javax.faces.view.facelets.Metadata;
import javax.faces.view.facelets.MetadataTarget;
import javax.faces.view.facelets.TagAttribute;
@@ -37,17 +36,45 @@
* @author Anton Belevich
*
*/
-public class AjaxBehaviorRule extends MetaRule {
+public class AjaxBehaviorRule extends BehaviorRule {
public static final Class<?>[] AJAX_BEHAVIOR_LISTENER_SIG = new Class[] {
AjaxBehaviorEvent.class };
public static final AjaxBehaviorRule INSTANCE = new AjaxBehaviorRule();
+ public static final String EXECUTE = "execute";
+
+ public static final String RENDER = "render";
+
+ public static final String LISTENER = "listener";
+
@Override
public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
{
+
if (meta.isTargetInstanceOf(AjaxBehavior.class)) {
- if ("ajaxBehaviorListener".equals(name)) {
- return new AjaxBehaviorListenerMapper(attribute);
+
+ if (!attribute.isLiteral()) {
+
+ if (LISTENER.equals(name)) {
+ return new AjaxBehaviorListenerMapper(attribute);
+ }
+
+ Class<?> type = meta.getPropertyType(name);
+
+ if (EXECUTE.equals(name) || RENDER.equals(name)) {
+ type = Object.class;
+ }
+
+ if (type == null) {
+ type = Object.class;
+ }
+
+ return new ValueExpressionMetadata(name, type, attribute);
+
+ } else if (meta != null && meta.getWriteMethod(name) != null) {
+ if (EXECUTE.equals(name) || RENDER.equals(name)) {
+ return new LiteralAttributeMetadata(name, attribute.getValue());
+ }
}
}
Modified:
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/tag/BehaviorRule.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/tag/BehaviorRule.java 2010-05-21
14:59:23 UTC (rev 17182)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/tag/BehaviorRule.java 2010-05-21
16:32:57 UTC (rev 17183)
@@ -80,35 +80,24 @@
@Override
public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
{
if (meta.isTargetInstanceOf(ClientBehavior.class)) {
- if (!attribute.isLiteral()) {
+ if (!attribute.isLiteral()) {
Class<?> type = meta.getPropertyType(name);
- //TODO nick -> anton - shouldn't this check be in
AjaxBehaviorRule?
- if ("execute".equals(name) || "render".equals(name))
{
+ if (type == null) {
type = Object.class;
- } else {
- type = meta.getPropertyType(name);
- if (type == null) {
- type = Object.class;
- }
}
-
+
return new ValueExpressionMetadata(name, type, attribute);
- } else {
- if (meta.getWriteMethod(name) != null) {
- //TODO nick -> anton - shouldn't this check be in
AjaxBehaviorRule?
- if ("execute".equals(name) ||
"render".equals(name)) {
- return new LiteralAttributeMetadata(name, attribute.getValue());
- }
- } else {
- if (log.isDebugEnabled()) {
- log.debug(attribute + " Property '" + name +
"' is not on type: "
+ } else if (meta != null && meta.getWriteMethod(name) == null) {
+
+ if (log.isDebugEnabled()) {
+ log
+ .debug(attribute + " Property '" + name +
"' is not on type: "
+ meta.getTargetClass().getName());
- }
- return new LiteralAttributeMetadata(name, attribute.getValue());
}
+ return new LiteralAttributeMetadata(name, attribute.getValue());
}
}