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 2012/05/22 17:07:04 UTC
svn commit: r1341514 -
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java
Author: lu4242
Date: Tue May 22 15:07:03 2012
New Revision: 1341514
URL: http://svn.apache.org/viewvc?rev=1341514&view=rev
Log:
MYFACES-3503 Improve exception handling for f:setPropertyActionListener and EL coercion (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=1341514&r1=1341513&r2=1341514&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 Tue May 22 15:07:03 2012
@@ -33,6 +33,7 @@ import javax.faces.event.AbortProcessing
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import javax.faces.view.ActionSource2AttachedObjectHandler;
+import javax.faces.view.Location;
import javax.faces.view.facelets.ComponentHandler;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
@@ -44,6 +45,8 @@ import javax.faces.view.facelets.TagHand
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletAttribute;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
import org.apache.myfaces.view.facelets.FaceletCompositionContext;
+import org.apache.myfaces.view.facelets.el.ContextAware;
+import org.apache.myfaces.view.facelets.el.ContextAwareELException;
@JSFFaceletTag(
name = "f:setPropertyActionListener",
@@ -126,7 +129,32 @@ public class SetPropertyActionListenerHa
// the "target" expression value type following the Expression
// Language coercion rules.
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
- value = expressionFactory.coerceToType(value, targetType);
+ try
+ {
+ value = expressionFactory.coerceToType(value, targetType);
+ }
+ catch (ELException e)
+ {
+ // Happens when type of attribute "value" is not convertible to type of attribute "target"
+ // by EL coercion rules.
+ // For example: value="#{10}" target="#{bean.booleanProperty}"
+ // In this case is not sure if problematic attribute is "value" or "target". But EL
+ // impls say:
+ // JUEL: "Cannot coerce from class java.lang.Long to class java.lang.Boolean"
+ // Tomcat EL: Cannot convert 10 of type class java.long.Long to class java.lang.Boolean
+ // Thus we report "value" attribute as exception source - that should be enough for user
+ // to solve the problem.
+ Location location = null;
+ // Wrapping of ValueExpressions to org.apache.myfaces.view.facelets.el.ContextAware
+ // can be disabled:
+ if (_value instanceof ContextAware)
+ {
+ ContextAware contextAware = (ContextAware) _value;
+ location = contextAware.getLocation();
+ }
+ throw new ContextAwareELException(location,
+ _value.getExpressionString(), "value", e);
+ }
}
// Call setValue()on the "target" ValueExpression with the resulting value.