You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/07/12 00:27:54 UTC

svn commit: r1145385 - /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java

Author: lu4242
Date: Mon Jul 11 22:27:54 2011
New Revision: 1145385

URL: http://svn.apache.org/viewvc?rev=1145385&view=rev
Log:
MYFACES-3209 Implement f:setPropertyActionListener according specification (thanks to Martin Koci for provide this patch)

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java?rev=1145385&r1=1145384&r2=1145385&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java Mon Jul 11 22:27:54 2011
@@ -23,6 +23,7 @@ import java.io.Serializable;
 
 import javax.el.ELContext;
 import javax.el.ELException;
+import javax.el.ExpressionFactory;
 import javax.el.ValueExpression;
 import javax.faces.FacesException;
 import javax.faces.component.ActionSource;
@@ -101,13 +102,33 @@ public class SetPropertyActionListenerHa
 
         public void processAction(ActionEvent evt) throws AbortProcessingException
         {
-            FacesContext faces = FacesContext.getCurrentInstance();
+            FacesContext facesContext = FacesContext.getCurrentInstance();
             
-            ELContext el = faces.getELContext();
+            ELContext elContext = facesContext.getELContext();
             
-            Object valueObj = _value.getValue(el);
+            // Spec f:setPropertyActionListener: 
             
-            _target.setValue(el, valueObj);
+            // Call getValue() on the "value" ValueExpression.
+            Object value = _value.getValue(elContext);
+            
+            // If value of the "value" expression is null, call setValue() on the "target" ValueExpression with the null
+            
+            // If the value of the "value" expression is not null, call getType()on the "value" and "target"
+            // ValueExpressions to determine their property types.
+            if (value != null)
+            {
+                Class<?> targetType = _target.getType(elContext);
+                // Spec says: "all getType() on the "value" to determine  property type" but it is not necessary
+                // beacuse type we have objValue already
+
+                //   Coerce the value of the "value" expression to the "target" expression value type following the Expression
+                // Language coercion rules. 
+                ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
+                value = expressionFactory.coerceToType(value, targetType);
+            }
+
+            // Call setValue()on the "target" ValueExpression with the resulting value.
+            _target.setValue(elContext, value);
         }
     }