Author: musachy Date: Fri Mar 20 02:03:03 2009 New Revision: 756301 URL: http://svn.apache.org/viewvc?rev=756301&view=rev Log: WW-3051 Throw exceptions when an EL expression fails due to an exception or because a property is missing
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Component.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Property.java struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java?rev=756301&r1=756300&r2=756301&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java Fri Mar 20 02:03:03 2009 @@ -195,4 +195,7 @@ /** The {...@link com.opensymphony.xwork2.UnknownHandlerManager} implementation class */ public static final String STRUTS_UNKNOWN_HANDLER_MANAGER = "struts.unknownHandlerManager"; + + /** Throw RuntimeException when a property is not found, or the evaluation of the espression fails*/ + public static final String STRUTS_EL_THROW_EXCEPTION = "struts.el.throwExceptionOnFailure"; } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Component.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Component.java?rev=756301&r1=756300&r2=756301&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Component.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Component.java Fri Mar 20 02:03:03 2009 @@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.struts2.StrutsException; +import org.apache.struts2.StrutsConstants; import org.apache.struts2.dispatcher.mapper.ActionMapper; import org.apache.struts2.dispatcher.mapper.ActionMapping; import org.apache.struts2.util.FastByteArrayOutputStream; @@ -56,6 +57,7 @@ protected ValueStack stack; protected Map parameters; protected ActionMapper actionMapper; + protected boolean throwExceptionOnELFailure; /** * Constructor. @@ -84,6 +86,11 @@ public void setActionMapper(ActionMapper mapper) { this.actionMapper = mapper; } + + @Inject(StrutsConstants.STRUTS_EL_THROW_EXCEPTION) + public void setThrowExceptionsOnELFailure(String throwException) { + this.throwExceptionOnELFailure = "true".equals(throwException); + } /** * Gets the OGNL value stack assoicated with this component. @@ -245,7 +252,7 @@ expr = stripExpressionIfAltSyntax(expr); - return getStack().findValue(expr); + return getStack().findValue(expr, throwExceptionOnELFailure); } /** @@ -372,7 +379,7 @@ } else { expr = stripExpressionIfAltSyntax(expr); - return getStack().findValue(expr, toType); + return getStack().findValue(expr, toType, throwExceptionOnELFailure); } } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Property.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Property.java?rev=756301&r1=756300&r2=756301&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Property.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Property.java Fri Mar 20 02:03:03 2009 @@ -26,11 +26,13 @@ import org.apache.struts2.views.annotations.StrutsTag; import org.apache.struts2.views.annotations.StrutsTagAttribute; +import org.apache.struts2.StrutsConstants; import com.opensymphony.xwork2.util.TextUtils; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; +import com.opensymphony.xwork2.inject.Inject; /** * <!-- START SNIPPET: javadoc --> @@ -136,7 +138,7 @@ // exception: don't call findString(), since we don't want the // expression parsed in this one case. it really // doesn't make sense, in fact. - actualValue = (String) getStack().findValue(value, String.class); + actualValue = (String) getStack().findValue(value, String.class, throwExceptionOnELFailure); try { if (actualValue != null) { Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties?rev=756301&r1=756300&r2=756301&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties (original) +++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties Fri Mar 20 02:03:03 2009 @@ -196,4 +196,8 @@ ### Whether to allow static method access in OGNL expressions or not struts.ognl.allowStaticMethodAccess=false +### Whether to throw a RuntimeException when a property is not found +### in an expression, or when the expression evaluation fails +struts.el.throwExceptionOnFailure=false + ### END SNIPPET: complete_file