You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2016/11/04 16:54:38 UTC
svn commit: r1768069 -
/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/EventHandler.java
Author: lofwyr
Date: Fri Nov 4 16:54:38 2016
New Revision: 1768069
URL: http://svn.apache.org/viewvc?rev=1768069&view=rev
Log:
TOBAGO-1617: New tag <tc:event> to be similar to <f:ajax> and to replace <tc:command> in facets
* setting the default in UIEvent from the Parent
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/EventHandler.java
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/EventHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/EventHandler.java?rev=1768069&r1=1768068&r2=1768069&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/EventHandler.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/EventHandler.java Fri Nov 4 16:54:38 2016
@@ -19,8 +19,10 @@
package org.apache.myfaces.tobago.facelets;
-import org.apache.myfaces.tobago.internal.behavior.EventBehavior;
import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.component.ClientBehaviors;
+import org.apache.myfaces.tobago.component.UIEvent;
+import org.apache.myfaces.tobago.internal.behavior.EventBehavior;
import javax.el.MethodExpression;
import javax.faces.component.PartialStateHolder;
@@ -91,25 +93,25 @@ public class EventHandler extends Tobago
if (!ComponentHandler.isNew(parent)) {
return;
}
- if (parent instanceof ClientBehaviorHolder) {
- //Apply this handler directly over the parent
- applyAttachedObject(ctx.getFacesContext(), parent);
+ if (parent instanceof ClientBehaviorHolder) {
+ //Apply this handler directly over the parent
+ applyAttachedObject(ctx.getFacesContext(), parent);
//todo } else if (UIComponent.isCompositeComponent(parent)) {
//todo FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);
- // It is supposed that for composite components, this tag should
- // add itself as a target, but note that on whole api does not exists
- // some tag that expose client behaviors as targets for composite
- // components. In RI, there exists a tag called composite:clientBehavior,
- // but does not appear on spec or javadoc, maybe because this could be
- // understand as an implementation detail, after all there exists a key
- // called AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY that could be
- // used to create a tag outside jsf implementation to attach targets.
+ // It is supposed that for composite components, this tag should
+ // add itself as a target, but note that on whole api does not exists
+ // some tag that expose client behaviors as targets for composite
+ // components. In RI, there exists a tag called composite:clientBehavior,
+ // but does not appear on spec or javadoc, maybe because this could be
+ // understand as an implementation detail, after all there exists a key
+ // called AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY that could be
+ // used to create a tag outside jsf implementation to attach targets.
//todo mctx.addAttachedObjectHandler(parent, this);
- } else {
- throw new TagException(this.tag,
- "Parent is not composite component or of type ClientBehaviorHolder, type is: "
- + parent);
- }
+ } else {
+ throw new TagException(this.tag,
+ "Parent is not composite component or of type ClientBehaviorHolder, type is: "
+ + parent);
+ }
}
/**
@@ -144,10 +146,10 @@ public class EventHandler extends Tobago
if (eventName == null) {
eventName = cvh.getDefaultEventName();
if (eventName == null) {
- throw new TagAttributeException(_event, "eventName could not be defined for f:ajax tag with no wrap mode.");
+ throw new TagAttributeException(_event, "eventName could not be defined for f:ajax tag with no wrap mode.");
}
} else if (!cvh.getEventNames().contains(eventName)) {
- throw new TagAttributeException(_event, "event it is not a valid eventName defined for this component");
+ throw new TagAttributeException(_event, "event it is not a valid eventName defined for this component");
}
Map<String, List<ClientBehavior>> clientBehaviors = cvh.getClientBehaviors();
@@ -174,6 +176,17 @@ public class EventHandler extends Tobago
return (EventBehavior) context.getApplication().createBehavior(EventBehavior.BEHAVIOR_ID);
}
+ @Override
+ public void onComponentCreated(FaceletContext faceletContext, UIComponent component, UIComponent parent) {
+ super.onComponentCreated(faceletContext, component, parent);
+
+ final UIEvent event = (UIEvent) component;
+ if (event.getEvent() == null) {
+ final ClientBehaviorHolder cvh = (ClientBehaviorHolder) parent;
+ event.setEvent(ClientBehaviors.valueOf(cvh.getDefaultEventName()));
+ }
+ }
+
/**
* The documentation says this attribute should not be used since it is not
* taken into account. Instead, getEventName is used on