You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2007/08/12 12:15:56 UTC

svn commit: r565033 - in /myfaces/tobago/trunk: contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java

Author: bommel
Date: Sun Aug 12 03:15:53 2007
New Revision: 565033

URL: http://svn.apache.org/viewvc?view=rev&rev=565033
Log:
(TOBAGO-466) Extend AttributeHandler for handling methodexpression in a facelet composition

Modified:
    myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java

Modified: myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java?view=diff&rev=565033&r1=565032&r2=565033
==============================================================================
--- myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java (original)
+++ myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java Sun Aug 12 03:15:53 2007
@@ -19,6 +19,7 @@
 
 import javax.el.ELException;
 import javax.el.MethodExpression;
+import javax.el.ExpressionFactory;
 import javax.faces.FacesException;
 import javax.faces.component.UIComponent;
 import javax.faces.component.EditableValueHolder;
@@ -74,17 +75,25 @@
         // TODO test expression
         ComponentUtil.setMarkup(parent, value.getValue());
       } else if (parent instanceof EditableValueHolder && TobagoConstants.ATTR_VALIDATOR.equals(nameValue)) {
-        MethodExpression methodExpression =
-            value.getMethodExpression(faceletContext, null, ComponentUtil.VALIDATOR_ARGS);
-        ((EditableValueHolder) parent).setValidator(new LegacyMethodBinding(methodExpression));
+        MethodExpression methodExpression =  getActionMethodExpression(faceletContext, null, ComponentUtil.VALIDATOR_ARGS);
+        if (methodExpression != null) {
+          // TODO jsf 1.2
+          ((EditableValueHolder) parent).setValidator(new LegacyMethodBinding(methodExpression));
+        }
+      } else if (parent instanceof EditableValueHolder && TobagoConstants.ATTR_VALUE_CHANGE_LISTENER.equals(nameValue)) {
+        MethodExpression methodExpression =  getActionMethodExpression(faceletContext, null, ComponentUtil.VALUE_CHANGE_LISTENER_ARGS);
+        if (methodExpression != null) {
+          // TODO jsf 1.2
+          ((EditableValueHolder) parent).setValueChangeListener(new LegacyMethodBinding(methodExpression));
+        }
       } else if (parent instanceof ActionSource && TobagoConstants.ATTR_ACTION.equals(nameValue)) {
-        MethodExpression action = getActionMethodExpression(faceletContext, ComponentUtil.ACTION_ARGS, String.class);
+        MethodExpression action = getActionMethodExpression(faceletContext, String.class, ComponentUtil.ACTION_ARGS);
         if (action != null) {
           // TODO jsf 1.2
           ((ActionSource) parent).setAction(new LegacyMethodBinding(action));
         }
       } else if (parent instanceof ActionSource && TobagoConstants.ATTR_ACTION_LISTENER.equals(nameValue)) {
-        MethodExpression action = getActionMethodExpression(faceletContext, ComponentUtil.ACTION_LISTENER_ARGS, null);
+        MethodExpression action = getActionMethodExpression(faceletContext, null, ComponentUtil.ACTION_LISTENER_ARGS);
         if (action != null) {
           // TODO jsf 1.2
           ((ActionSource) parent).setActionListener(new LegacyMethodBinding(action));
@@ -99,13 +108,15 @@
     }
   }
 
-  private MethodExpression getActionMethodExpression(FaceletContext faceletContext, Class [] args, Class returnType) {
+  private MethodExpression getActionMethodExpression(FaceletContext faceletContext, Class returnType, Class[] args) {
+    // in a composition we get the method expression may be from a value expression
+    // the method expression can be empty
+    // in this case return nothing
     if (value.getValue().startsWith("$")) {
       Object obj = value.getValueExpression(faceletContext, String.class).getValue(faceletContext);
       if (obj != null && obj instanceof String && ((String) obj).length() > 0) {
-        TagAttribute attribute = new TagAttribute(value.getLocation(), value.getNamespace(),
-            value.getLocalName(), value.getQName(), (String) obj);
-        return attribute.getMethodExpression(faceletContext, returnType, args);
+        ExpressionFactory expressionFactory = faceletContext.getExpressionFactory();
+        return expressionFactory.createMethodExpression(faceletContext, (String) obj, returnType, args);
       }
     } else {
       return value.getMethodExpression(faceletContext, returnType, args);

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java?view=diff&rev=565033&r1=565032&r2=565033
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/TobagoConstants.java Sun Aug 12 03:15:53 2007
@@ -164,6 +164,7 @@
   public static final String ATTR_TRANSITION = "transition";
   public static final String ATTR_TYPE = "type";
   public static final String ATTR_VALUE = "value";
+  public static final String ATTR_VALUE_CHANGE_LISTENER = "valueChangeListener";
   public static final String ATTR_VAR = "var";
   public static final String ATTR_UNIT = "unit";
   public static final String ATTR_UPDATE = "update";