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:28 UTC
svn commit: r1341516 -
/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java
Author: lu4242
Date: Tue May 22 15:07:28 2012
New Revision: 1341516
URL: http://svn.apache.org/viewvc?rev=1341516&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/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java?rev=1341516&r1=1341515&r2=1341516&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java Tue May 22 15:07:28 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",
@@ -62,8 +65,8 @@ public class SetPropertyActionListenerHa
this._target = this.getRequiredAttribute("target");
}
- public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
- ELException
+ public void apply(FaceletContext ctx, UIComponent parent)
+ throws IOException, FacesException, FaceletException, ELException
{
//Apply only if we are creating a new component
if (!ComponentHandler.isNew(parent))
@@ -81,7 +84,8 @@ public class SetPropertyActionListenerHa
}
else
{
- throw new TagException(this.tag, "Parent is not composite component or of type ActionSource, type is: " + parent);
+ throw new TagException(this.tag,
+ "Parent is not composite component or of type ActionSource, type is: " + parent);
}
}
@@ -121,10 +125,36 @@ public class SetPropertyActionListenerHa
// 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
+ // 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);
+ 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.