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/09/12 21:25:50 UTC
svn commit: r1169885 [1/2] - in /myfaces/core/branches/2.0.x:
api/src/main/java/javax/faces/component/ api/src/main/java/javax/faces/event/
api/src/main/java/javax/faces/validator/
impl/src/main/java/org/apache/myfaces/application/ impl/src/main/java/o...
Author: lu4242
Date: Mon Sep 12 19:25:49 2011
New Revision: 1169885
URL: http://svn.apache.org/viewvc?rev=1169885&view=rev
Log:
MYFACES-3202 Improve EL Exceptions wrapping, MYFACES-3199 Handling AbortProcessingException is unconsistent and MYFACES-3301 ValidatorExceptions are not properly handled in MethodExpressionValidator.validate()
Added:
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareException.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagMethodExpression.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagValueExpression.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagValueExpressionUEL.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareUtils.java
myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/view/facelets/ExceptionNoWrapContextAwareTestCase.java
myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/view/facelets/ExceptionTestCase.java
myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/testActionException1.xhtml
myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/testActionListenerException1.xhtml
myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/testValidatorException1.xhtml
myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/testValidatorException2.xhtml
myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/testValueChangeListenerException1.xhtml
Modified:
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentUtils.java
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/event/MethodExpressionActionListener.java
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/event/MethodExpressionValueChangeListener.java
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/validator/MethodExpressionValidator.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/ActionListenerImpl.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareELException.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareMethodNotFoundException.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwarePropertyNotFoundException.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagMethodExpression.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpression.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributeImpl.java
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentUtils.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentUtils.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentUtils.java Mon Sep 12 19:25:49 2011
@@ -300,42 +300,38 @@ class _ComponentUtils
catch (EvaluationException e)
{
input.setValid(false);
-
- // we need to check for a ValidatorException
- Throwable cause = e;
- while ((cause = cause.getCause()) != null)
+ Throwable cause = e.getCause();
+ if (cause instanceof ValidatorException)
{
- if (cause instanceof ValidatorException)
+ String validatorMessage = input.getValidatorMessage();
+ if (validatorMessage != null)
+ {
+ context.addMessage(input.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ validatorMessage, validatorMessage));
+ }
+ else
{
- String validatorMessage = input.getValidatorMessage();
- if (validatorMessage != null)
+ FacesMessage facesMessage = ((ValidatorException)cause).getFacesMessage();
+ if (facesMessage != null)
{
- context.addMessage(input.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR,
- validatorMessage, validatorMessage));
+ facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
+ context.addMessage(input.getClientId(context), facesMessage);
}
- else
+ Collection<FacesMessage> facesMessages = ((ValidatorException)cause).getFacesMessages();
+ if (facesMessages != null)
{
- FacesMessage facesMessage = ((ValidatorException)cause).getFacesMessage();
- if (facesMessage != null)
- {
- facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
- context.addMessage(input.getClientId(context), facesMessage);
- }
- Collection<FacesMessage> facesMessages = ((ValidatorException)cause).getFacesMessages();
- if (facesMessages != null)
+ for (FacesMessage message : facesMessages)
{
- for (FacesMessage message : facesMessages)
- {
- message.setSeverity(FacesMessage.SEVERITY_ERROR);
- context.addMessage(input.getClientId(context), message);
- }
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ context.addMessage(input.getClientId(context), message);
}
}
}
}
-
- // no ValidatorException found, re-throw EvaluationException
- throw e;
+ else
+ {
+ throw e;
+ }
}
}
}
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/event/MethodExpressionActionListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/event/MethodExpressionActionListener.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/event/MethodExpressionActionListener.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/event/MethodExpressionActionListener.java Mon Sep 12 19:25:49 2011
@@ -20,6 +20,7 @@
package javax.faces.event;
import javax.el.ELContext;
+import javax.el.ELException;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.MethodNotFoundException;
@@ -83,22 +84,53 @@ public class MethodExpressionActionListe
methodExpressionZeroArg.invoke(getElContext(), EMPTY_PARAMS);
}
}
- catch (Exception e)
+ catch (ELException e)
{
- // If that fails for any reason, throw an AbortProcessingException, including the cause of the failure
+ // "... If that fails for any reason, throw an AbortProcessingException, including the cause of the failure ..."
+ // -= Leonardo Uribe =- after discussing this topic on MYFACES-3199, the conclusion is the part is an advice
+ // for the developer implementing a listener in a method expressions that could be wrapped by this class.
+ // The spec wording is poor but, to keep this coherently with ExceptionHandler API, the spec and code on UIViewRoot we need:
+ // 2a) "exception is instance of APE or any of the causes of the exception are an APE,
+ // DON'T publish ExceptionQueuedEvent and terminate processing for current event".
+ // 2b) for any other exception publish ExceptionQueuedEvent and continue broadcast processing.
Throwable cause = e.getCause();
- if (cause == null)
+ AbortProcessingException ape = null;
+ if (cause != null)
{
- cause = e;
+ do
+ {
+ if (cause != null && cause instanceof AbortProcessingException)
+ {
+ ape = (AbortProcessingException) cause;
+ break;
+ }
+ cause = cause.getCause();
+ }
+ while (cause != null);
}
- if (cause instanceof AbortProcessingException)
+
+ if (ape != null)
{
- throw (AbortProcessingException) cause;
- }
- else
- {
- throw new AbortProcessingException(cause);
+ // 2a) "exception is instance of APE or any of the causes of the exception are an APE,
+ // DON'T publish ExceptionQueuedEvent and terminate processing for current event".
+ // To do this throw an AbortProcessingException here, later on UIViewRoot.broadcastAll,
+ // this exception will be received and stored to handle later.
+ throw ape;
}
+ throw e;
+ //Throwable cause = e.getCause();
+ //if (cause == null)
+ //{
+ // cause = e;
+ //}
+ //if (cause instanceof AbortProcessingException)
+ //{
+ // throw (AbortProcessingException) cause;
+ //}
+ //else
+ //{
+ // throw new AbortProcessingException(cause);
+ //}
}
}
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/event/MethodExpressionValueChangeListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/event/MethodExpressionValueChangeListener.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/event/MethodExpressionValueChangeListener.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/event/MethodExpressionValueChangeListener.java Mon Sep 12 19:25:49 2011
@@ -19,6 +19,7 @@
package javax.faces.event;
import javax.el.ELContext;
+import javax.el.ELException;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.MethodNotFoundException;
@@ -83,22 +84,54 @@ public class MethodExpressionValueChange
methodExpressionZeroArg.invoke(getElContext(), EMPTY_PARAMS);
}
}
- catch (Exception e)
+ catch (ELException e)
{
- // If that fails for any reason, throw an AbortProcessingException, including the cause of the failure
+ // "... If that fails for any reason, throw an AbortProcessingException, including the cause of the failure ..."
+ // -= Leonardo Uribe =- after discussing this topic on MYFACES-3199, the conclusion is the part is an advice
+ // for the developer implementing a listener in a method expressions that could be wrapped by this class.
+ // The spec wording is poor but, to keep this coherently with ExceptionHandler API, the spec and code on UIViewRoot we need:
+ // 2a) "exception is instance of APE or any of the causes of the exception are an APE,
+ // DON'T publish ExceptionQueuedEvent and terminate processing for current event".
+ // 2b) for any other exception publish ExceptionQueuedEvent and continue broadcast processing.
Throwable cause = e.getCause();
- if (cause == null)
+ AbortProcessingException ape = null;
+ if (cause != null)
{
- cause = e;
+ do
+ {
+ if (cause != null && cause instanceof AbortProcessingException)
+ {
+ ape = (AbortProcessingException) cause;
+ break;
+ }
+ cause = cause.getCause();
+ }
+ while (cause != null);
}
- if (cause instanceof AbortProcessingException)
+
+ if (ape != null)
{
- throw (AbortProcessingException) cause;
- }
- else
- {
- throw new AbortProcessingException(cause);
+ // 2a) "exception is instance of APE or any of the causes of the exception are an APE,
+ // DON'T publish ExceptionQueuedEvent and terminate processing for current event".
+ // To do this throw an AbortProcessingException here, later on UIViewRoot.broadcastAll,
+ // this exception will be received and stored to handle later.
+ throw ape;
}
+ //for any other exception publish ExceptionQueuedEvent and continue broadcast processing.
+ throw e;
+ //Throwable cause = e.getCause();
+ //if (cause == null)
+ //{
+ // cause = e;
+ //}
+ //if (cause instanceof AbortProcessingException)
+ //{
+ // throw (AbortProcessingException) cause;
+ //}
+ //else
+ //{
+ // throw new AbortProcessingException(cause);
+ //}
}
}
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/validator/MethodExpressionValidator.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/validator/MethodExpressionValidator.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/validator/MethodExpressionValidator.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/validator/MethodExpressionValidator.java Mon Sep 12 19:25:49 2011
@@ -63,18 +63,38 @@ public class MethodExpressionValidator i
}
catch (ELException e)
{
- // we need to check for a ValidatorException
- Throwable cause = e;
- while ((cause = cause.getCause()) != null)
+ Throwable cause = e.getCause();
+ ValidatorException vex = null;
+ if (cause != null)
{
- if (cause instanceof ValidatorException)
+ do
{
- throw (ValidatorException)cause;
+ if (cause != null && cause instanceof ValidatorException)
+ {
+ vex = (ValidatorException) cause;
+ break;
+ }
+ cause = cause.getCause();
}
+ while (cause != null);
}
-
- // no ValidatorException found, re-throw ELException
- throw e;
+ if (vex != null)
+ {
+ throw vex;
+ }
+ else
+ {
+ throw e;
+ }
+ //Throwable cause = e.getCause();
+ //if (cause instanceof ValidatorException)
+ //{
+ // throw (ValidatorException)cause;
+ //}
+ //else
+ //{
+ // throw e;
+ //}
}
}
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/ActionListenerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/ActionListenerImpl.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/ActionListenerImpl.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/ActionListenerImpl.java Mon Sep 12 19:25:49 2011
@@ -53,16 +53,15 @@ public class ActionListenerImpl implemen
String fromAction = null;
String outcome = null;
- // Backwards compatibility for pre-1.2.
-
- if (component instanceof ActionSource) {
- methodBinding = ((ActionSource) component).getAction();
+ if (component instanceof ActionSource2)
+ {
+ // Must be an instance of ActionSource2, so don't look on action if the actionExpression is set
+ methodExpression = ((ActionSource2) component).getActionExpression();
}
-
- else {
- // Must be an instance of ActionSource2.
-
- methodExpression = ((ActionSource2) component).getActionExpression();
+ if (methodExpression == null && component instanceof ActionSource)
+ {
+ // Backwards compatibility for pre-1.2.
+ methodBinding = ((ActionSource) component).getAction();
}
if (methodExpression != null)
@@ -78,14 +77,41 @@ public class ActionListenerImpl implemen
}
catch (ELException e)
{
+ // "... If that fails for any reason, throw an AbortProcessingException, including the cause of the failure ..."
+ // -= Leonardo Uribe =- after discussing this topic on MYFACES-3199, the conclusion is the part is an advice
+ // for the developer implementing a listener in a method expressions that could be wrapped by this class.
+ // The spec wording is poor but, to keep this coherently with ExceptionHandler API, the spec and code on UIViewRoot we need:
+ // 2a) "exception is instance of APE or any of the causes of the exception are an APE,
+ // DON'T publish ExceptionQueuedEvent and terminate processing for current event".
+ // 2b) for any other exception publish ExceptionQueuedEvent and continue broadcast processing.
Throwable cause = e.getCause();
- if (cause != null && cause instanceof AbortProcessingException)
+ AbortProcessingException ape = null;
+ if (cause != null)
{
- throw (AbortProcessingException)cause;
+ do
+ {
+ if (cause != null && cause instanceof AbortProcessingException)
+ {
+ ape = (AbortProcessingException) cause;
+ break;
+ }
+ cause = cause.getCause();
+ }
+ while (cause != null);
}
-
- throw new FacesException("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e);
+ if (ape != null)
+ {
+ // 2a) "exception is instance of APE or any of the causes of the exception are an APE,
+ // DON'T publish ExceptionQueuedEvent and terminate processing for current event".
+ // To do this throw an AbortProcessingException here, later on UIViewRoot.broadcastAll,
+ // this exception will be received and stored to handle later.
+ throw ape;
+ }
+
+ // Since this ActionListener is the one who handles navigation, if we have another different exception
+ // here we can't queue it on ExceptionHandler stack, instead throw it as a FacesException.
+ throw new FacesException("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e);
}
catch (RuntimeException e)
{
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java Mon Sep 12 19:25:49 2011
@@ -76,6 +76,7 @@ import org.apache.myfaces.shared.util.St
import org.apache.myfaces.spi.WebConfigProvider;
import org.apache.myfaces.spi.WebConfigProviderFactory;
import org.apache.myfaces.view.facelets.component.UIRepeat;
+import org.apache.myfaces.view.facelets.el.ContextAware;
/**
* This class provides utility methods to generate the
@@ -766,9 +767,24 @@ public final class ErrorPageWriter
private static void _writeCause(Writer writer, Throwable ex) throws IOException
{
String msg = ex.getMessage();
+ String contextAwareLocation = null;
+ if (ex instanceof ContextAware)
+ {
+ ContextAware caex = (ContextAware) ex;
+ contextAwareLocation = caex.getLocation().toString() + " " +
+ caex.getQName() + "=\"" +
+ caex.getExpressionString() + "\"";
+ }
while (ex.getCause() != null)
{
ex = ex.getCause();
+ if (ex instanceof ContextAware)
+ {
+ ContextAware caex = (ContextAware) ex;
+ contextAwareLocation = caex.getLocation().toString() + " " +
+ caex.getQName() + "=\"" +
+ caex.getExpressionString() + "\"";
+ }
if (ex.getMessage() != null)
msg = ex.getMessage();
}
@@ -784,6 +800,13 @@ public final class ErrorPageWriter
}
StackTraceElement stackTraceElement = ex.getStackTrace()[0];
writer.write("<br/> at " + stackTraceElement.toString());
+
+ if (contextAwareLocation != null)
+ {
+ writer.write("<br/> <br/>");
+ writer.write(contextAwareLocation);
+ writer.write("<br/>");
+ }
}
private static void _writeVariables(Writer writer, FacesContext faces, UIViewRoot view) throws IOException
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java Mon Sep 12 19:25:49 2011
@@ -342,4 +342,14 @@ abstract public class FaceletComposition
{
return ELExpressionCacheMode.noCache;
}
+
+ /**
+ *
+ * @since 2.0.9
+ * @return
+ */
+ public boolean isWrapTagExceptionsAsContextAware()
+ {
+ return true;
+ }
}
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareELException.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareELException.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareELException.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareELException.java Mon Sep 12 19:25:49 2011
@@ -31,11 +31,21 @@ import javax.faces.view.Location;
*/
public class ContextAwareELException extends ELException implements ContextAwareExceptionWrapper {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2231893442274827689L;
+
private ContextAwareExceptionWrapper _delegate;
+ //private Throwable _wrappedException;
+ //private String _localizedMessage;
public ContextAwareELException(Location location, String expressionString,
String qName, Throwable wrapped) {
super(wrapped);
+ //super(wrapped.getMessage());
+ //_localizedMessage = wrapped.getLocalizedMessage();
+ //_wrappedException = wrapped;
_delegate = new DefaultContextAwareELException(location, expressionString, qName, wrapped);
}
@@ -54,4 +64,23 @@ public class ContextAwareELException ext
public Location getLocation() {
return _delegate.getLocation();
}
+
+ /*
+ @Override
+ public String getLocalizedMessage()
+ {
+ return _localizedMessage;
+ }
+
+ @Override
+ public Throwable getCause()
+ {
+ return _wrappedException.getCause();
+ }
+
+ @Override
+ public synchronized Throwable initCause(Throwable cause)
+ {
+ return _wrappedException.initCause(cause);
+ }*/
}
Added: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareException.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareException.java?rev=1169885&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareException.java (added)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareException.java Mon Sep 12 19:25:49 2011
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.view.facelets.el;
+
+import javax.el.ELException;
+import javax.faces.FacesWrapper;
+import javax.faces.view.Location;
+
+/**
+ * Implementation of types {@link ELException}, {@link ContextAware} and {@link FacesWrapper}
+ *
+ * @author martinkoci
+ *
+ * @see ContextAware
+ */
+public class ContextAwareException extends RuntimeException implements ContextAwareExceptionWrapper {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7239367504106332588L;
+
+ private ContextAwareExceptionWrapper _delegate;
+
+ public ContextAwareException(Location location, String expressionString,
+ String qName, Throwable wrapped) {
+ super(wrapped);
+ _delegate = new DefaultContextAwareELException(location, expressionString, qName, wrapped);
+ }
+
+ public String getExpressionString() {
+ return _delegate.getExpressionString();
+ }
+
+ public String getQName() {
+ return _delegate.getQName();
+ }
+
+ public Throwable getWrapped() {
+ return _delegate.getWrapped();
+ }
+
+ public Location getLocation() {
+ return _delegate.getLocation();
+ }
+}
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareMethodNotFoundException.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareMethodNotFoundException.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareMethodNotFoundException.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareMethodNotFoundException.java Mon Sep 12 19:25:49 2011
@@ -31,11 +31,21 @@ import javax.faces.view.Location;
*/
public class ContextAwareMethodNotFoundException extends MethodNotFoundException implements ContextAwareExceptionWrapper {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8172862923048615707L;
+
private ContextAwareExceptionWrapper _delegate;
+ //private Throwable _wrappedException;
+ //private String _localizedMessage;
public ContextAwareMethodNotFoundException(Location location,
String expressionString, String qName, Throwable wrapped) {
- super(wrapped);
+ super(wrapped);
+ //super(wrapped.getMessage());
+ //_localizedMessage = wrapped.getLocalizedMessage();
+ //_wrappedException = wrapped;
_delegate = new DefaultContextAwareELException(location, expressionString, qName, wrapped);
}
@@ -55,4 +65,22 @@ public class ContextAwareMethodNotFoundE
return _delegate.getQName();
}
+ /*
+ @Override
+ public String getLocalizedMessage()
+ {
+ return _localizedMessage;
+ }
+
+ @Override
+ public Throwable getCause()
+ {
+ return _wrappedException.getCause();
+ }
+
+ @Override
+ public synchronized Throwable initCause(Throwable cause)
+ {
+ return _wrappedException.initCause(cause);
+ }*/
}
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwarePropertyNotFoundException.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwarePropertyNotFoundException.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwarePropertyNotFoundException.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwarePropertyNotFoundException.java Mon Sep 12 19:25:49 2011
@@ -31,12 +31,23 @@ import javax.faces.view.Location;
*/
public class ContextAwarePropertyNotFoundException extends javax.el.PropertyNotFoundException implements ContextAwareExceptionWrapper {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -4194177998555929451L;
+
private ContextAwareExceptionWrapper _delegate;
+ //private Throwable _wrappedException;
+ //private String _localizedMessage;
+
public ContextAwarePropertyNotFoundException(Location location,
String expressionString, String qName,
Throwable wrapped) {
super(wrapped);
+ //super(wrapped.getMessage());
+ //_localizedMessage = wrapped.getLocalizedMessage();
+ //_wrappedException = wrapped;
_delegate = new DefaultContextAwareELException(location, expressionString, qName, wrapped);
}
@@ -56,5 +67,22 @@ public class ContextAwarePropertyNotFoun
return _delegate.getWrapped();
}
+ /*
+ @Override
+ public String getLocalizedMessage()
+ {
+ return _localizedMessage;
+ }
+
+ @Override
+ public Throwable getCause()
+ {
+ return _wrappedException.getCause();
+ }
+ @Override
+ public synchronized Throwable initCause(Throwable cause)
+ {
+ return _wrappedException.initCause(cause);
+ }*/
}
Added: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagMethodExpression.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagMethodExpression.java?rev=1169885&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagMethodExpression.java (added)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagMethodExpression.java Mon Sep 12 19:25:49 2011
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.view.facelets.el;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.MethodExpression;
+import javax.el.MethodInfo;
+import javax.el.MethodNotFoundException;
+import javax.el.PropertyNotFoundException;
+import javax.faces.FacesWrapper;
+import javax.faces.view.Location;
+import javax.faces.view.facelets.TagAttribute;
+
+/**
+ *
+ *
+ * @author Jacob Hookom
+ * @version $Id: TagMethodExpression.java,v 1.7 2008/07/13 19:01:43 rlubke Exp $
+ */
+public final class ContextAwareTagMethodExpression extends MethodExpression implements Externalizable, FacesWrapper<MethodExpression>, ContextAware
+{
+
+ private static final long serialVersionUID = 1L;
+
+ private MethodExpression _wrapped;
+
+ private Location _location;
+
+ private String _qName;
+
+ public ContextAwareTagMethodExpression()
+ {
+ super();
+ }
+
+ public ContextAwareTagMethodExpression(TagAttribute tagAttribute, MethodExpression methodExpression)
+ {
+ _location = tagAttribute.getLocation();
+ _qName = tagAttribute.getQName();
+ _wrapped = methodExpression;
+ }
+
+ public MethodInfo getMethodInfo(ELContext context)
+ {
+ try
+ {
+ return _wrapped.getMethodInfo(context);
+ }
+ catch (PropertyNotFoundException pnfe)
+ {
+ throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
+ }
+ catch (MethodNotFoundException mnfe)
+ {
+ throw new ContextAwareMethodNotFoundException(getLocation(), getLocalExpressionString(), getQName(), mnfe);
+ }
+ catch (ELException e)
+ {
+ throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
+ }
+ //Not necessary because NullPointerException by null context never occur and should not be wrapped
+ //catch (Exception e)
+ //{
+ // throw new ContextAwareException(getLocation(), getLocalExpressionString(), getQName(), e);
+ //}
+ }
+
+ public Object invoke(ELContext context, Object[] params)
+ {
+ try
+ {
+ return _wrapped.invoke(context, params);
+ }
+ catch (PropertyNotFoundException pnfe)
+ {
+ throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
+ }
+ catch (MethodNotFoundException mnfe)
+ {
+ throw new ContextAwareMethodNotFoundException(getLocation(), getLocalExpressionString(), getQName(), mnfe);
+ }
+ catch (ELException e)
+ {
+ throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
+ }
+ //Not necessary because NullPointerException by null context never occur and should not be wrapped
+ //catch (Exception e)
+ //{
+ // throw new ContextAwareException(getLocation(), getLocalExpressionString(), getQName(), e);
+ //}
+ }
+
+
+ private String getLocalExpressionString()
+ {
+ String expressionString = null;
+ try
+ {
+ expressionString = getExpressionString();
+ }
+ catch (Throwable t)
+ {
+ //swallo it because it is not important
+ }
+ return expressionString;
+ }
+
+ public String getExpressionString()
+ {
+ return _wrapped.getExpressionString();
+ }
+
+ public boolean equals(Object obj)
+ {
+ return _wrapped.equals(obj);
+ }
+
+ public int hashCode()
+ {
+ return _wrapped.hashCode();
+ }
+
+ public boolean isLiteralText()
+ {
+ return _wrapped.isLiteralText();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeObject(_wrapped);
+ out.writeObject(_location);
+ out.writeUTF(_qName);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ _wrapped = (MethodExpression) in.readObject();
+ _location = (Location) in.readObject();
+ _qName = in.readUTF();
+ }
+
+ public String toString()
+ {
+ return _location + ": " + _wrapped;
+ }
+
+ public Location getLocation() {
+ return _location;
+ }
+
+ public String getQName() {
+ return _qName;
+ }
+
+ public MethodExpression getWrapped() {
+ return _wrapped;
+ }
+
+}
Added: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagValueExpression.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagValueExpression.java?rev=1169885&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagValueExpression.java (added)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagValueExpression.java Mon Sep 12 19:25:49 2011
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.view.facelets.el;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.PropertyNotFoundException;
+import javax.el.PropertyNotWritableException;
+import javax.el.ValueExpression;
+import javax.faces.FacesWrapper;
+import javax.faces.view.Location;
+import javax.faces.view.facelets.TagAttribute;
+
+/**
+ *
+ *
+ * @author Jacob Hookom
+ * @version $Id: TagValueExpression.java,v 1.7 2008/07/13 19:01:42 rlubke Exp $
+ */
+public class ContextAwareTagValueExpression extends ValueExpression implements Externalizable, FacesWrapper<ValueExpression>, ContextAware
+{
+
+ private static final long serialVersionUID = 1L;
+
+ private ValueExpression _wrapped;
+
+ private Location _location;
+
+ private String _qName;
+
+ public ContextAwareTagValueExpression()
+ {
+ super();
+ }
+
+ public ContextAwareTagValueExpression(TagAttribute tagAttribute, ValueExpression valueExpression)
+ {
+ _location = tagAttribute.getLocation();
+ _qName = tagAttribute.getQName();
+ _wrapped = valueExpression;
+ }
+
+ public Class<?> getExpectedType()
+ {
+ return _wrapped.getExpectedType();
+ }
+
+ public Class<?> getType(ELContext context)
+ {
+ try
+ {
+ return _wrapped.getType(context);
+ }
+ catch (PropertyNotFoundException pnfe)
+ {
+ throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
+ }
+ catch (ELException e)
+ {
+ throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
+ }
+ //Not necessary because NullPointerException by null context never occur and should not be wrapped
+ //catch (Exception e)
+ //{
+ // throw new ContextAwareException(getLocation(), getLocalExpressionString(), getQName(), e);
+ //}
+ }
+
+ public Object getValue(ELContext context)
+ {
+ try
+ {
+ return _wrapped.getValue(context);
+ }
+ catch (PropertyNotFoundException pnfe)
+ {
+ throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
+ }
+ catch (ELException e)
+ {
+ throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
+ }
+ //Not necessary because NullPointerException by null context never occur and should not be wrapped
+ //catch (Exception e)
+ //{
+ // throw new ContextAwareException(getLocation(), getLocalExpressionString(), getQName(), e);
+ //}
+ }
+
+ private String getLocalExpressionString()
+ {
+ String expressionString = null;
+ try
+ {
+ expressionString = getExpressionString();
+ }
+ catch (Throwable t)
+ {
+ //swallo it because it is not important
+ }
+ return expressionString;
+ }
+
+ public boolean isReadOnly(ELContext context)
+ {
+ try
+ {
+ return _wrapped.isReadOnly(context);
+ }
+ catch (PropertyNotFoundException pnfe)
+ {
+ throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
+ }
+ catch (ELException e)
+ {
+ throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
+ }
+ //Not necessary because NullPointerException by null context never occur and should not be wrapped
+ //catch (Exception e)
+ //{
+ // throw new ContextAwareException(getLocation(), getLocalExpressionString(), getQName(), e);
+ //}
+
+ }
+
+ public void setValue(ELContext context, Object value)
+ {
+ try
+ {
+ _wrapped.setValue(context, value);
+ }
+ catch (PropertyNotFoundException pnfe)
+ {
+ throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
+ }
+ catch (PropertyNotWritableException pnwe)
+ {
+ throw new ContextAwarePropertyNotWritableException(getLocation(), getLocalExpressionString(), getQName(), pnwe);
+ }
+ catch (ELException e)
+ {
+ throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
+ }
+ //Not necessary because NullPointerException by null context never occur and should not be wrapped
+ //catch (Exception e)
+ //{
+ // throw new ContextAwareException(getLocation(), getLocalExpressionString(), getQName(), e);
+ //}
+ }
+
+ public boolean equals(Object obj)
+ {
+ return _wrapped.equals(obj);
+ }
+
+ public String getExpressionString()
+ {
+ return _wrapped.getExpressionString();
+ }
+
+ public int hashCode()
+ {
+ return _wrapped.hashCode();
+ }
+
+ public boolean isLiteralText()
+ {
+ return _wrapped.isLiteralText();
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ _wrapped = (ValueExpression) in.readObject();
+ _location = (Location) in.readObject();
+ _qName = in.readUTF();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeObject(_wrapped);
+ out.writeObject(_location);
+ out.writeUTF(_qName);
+ }
+
+ public String toString()
+ {
+ return _location + ": " + _wrapped;
+ }
+
+ public ValueExpression getWrapped()
+ {
+ return _wrapped;
+ }
+
+ public Location getLocation() {
+ return _location;
+ }
+
+ public String getQName() {
+ return _qName;
+ }
+}
Added: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagValueExpressionUEL.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagValueExpressionUEL.java?rev=1169885&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagValueExpressionUEL.java (added)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareTagValueExpressionUEL.java Mon Sep 12 19:25:49 2011
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.view.facelets.el;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.PropertyNotFoundException;
+import javax.el.ValueExpression;
+import javax.el.ValueReference;
+import javax.faces.view.facelets.TagAttribute;
+
+/**
+ * TagValueExpression for el-api 2.2
+ *
+ * @author Jakob Korherr (latest modification by $Author: lu4242 $)
+ * @version $Revision: 1150175 $ $Date: 2011-07-23 12:37:25 -0500 (Sáb, 23 Jul 2011) $
+ */
+public class ContextAwareTagValueExpressionUEL extends ContextAwareTagValueExpression
+{
+
+ public ContextAwareTagValueExpressionUEL()
+ {
+ super();
+ }
+
+ public ContextAwareTagValueExpressionUEL(TagAttribute attr, ValueExpression orig)
+ {
+ super(attr, orig);
+ }
+
+ @Override
+ public ValueReference getValueReference(ELContext context)
+ {
+ try
+ {
+ return getWrapped().getValueReference(context);
+ }
+ catch (PropertyNotFoundException pnfe)
+ {
+ throw new ContextAwarePropertyNotFoundException(getLocation(), getExpressionString(), getQName() , pnfe);
+ }
+ catch (ELException e)
+ {
+ throw new ContextAwareELException(getLocation(), getExpressionString(), getQName(), e);
+ }
+ //Not necessary because NullPointerException by null context never occur and should not be wrapped
+ //catch (Exception e) {
+ // throw new ContextAwareException(getLocation(), getExpressionString(), getQName(), e);
+ //}
+ }
+
+}
Added: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareUtils.java?rev=1169885&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareUtils.java (added)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/ContextAwareUtils.java Mon Sep 12 19:25:49 2011
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.view.facelets.el;
+
+import javax.el.ELContext;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
+import org.apache.myfaces.shared.util.WebConfigParamUtils;
+
+public class ContextAwareUtils
+{
+ /**
+ * Wrap exception caused by calls to EL expressions, so information like the location, expression string and tag name can be retrieved by
+ * the ExceptionHandler implementation and used to output meaningful information about itself.
+ *
+ * <p>Note in some cases this will wrap the original javax.el.ELException, so the information will not be on the stack trace unless ExceptionHandler
+ * retrieve checking if the exception implements ContextAware interface and calling getWrapped() method.
+ * </p>
+ *
+ */
+ @JSFWebConfigParam(since="2.0.9, 2.1.3" , defaultValue="true", expectedValues="true, false")
+ public static final String INIT_PARAM_WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE = "org.apache.myfaces.WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE";
+
+ public static boolean isWrapTagExceptionsAsContextAware(ELContext context)
+ {
+ FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
+ facesContext = facesContext == null ? FacesContext.getCurrentInstance() : facesContext;
+ if (facesContext != null)
+ {
+ return WebConfigParamUtils.getBooleanInitParameter(facesContext.getExternalContext(),
+ INIT_PARAM_WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE, true);
+ }
+ else
+ {
+ //No facesContext, return false
+ return false;
+ }
+ }
+}
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagMethodExpression.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagMethodExpression.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagMethodExpression.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagMethodExpression.java Mon Sep 12 19:25:49 2011
@@ -30,7 +30,6 @@ import javax.el.MethodInfo;
import javax.el.MethodNotFoundException;
import javax.el.PropertyNotFoundException;
import javax.faces.FacesWrapper;
-import javax.faces.view.Location;
import javax.faces.view.facelets.TagAttribute;
/**
@@ -39,50 +38,42 @@ import javax.faces.view.facelets.TagAttr
* @author Jacob Hookom
* @version $Id: TagMethodExpression.java,v 1.7 2008/07/13 19:01:43 rlubke Exp $
*/
-public final class TagMethodExpression extends MethodExpression implements Externalizable, FacesWrapper<MethodExpression>, ContextAware
+public final class TagMethodExpression extends MethodExpression implements Externalizable, FacesWrapper<MethodExpression>
{
private static final long serialVersionUID = 1L;
- private MethodExpression _wrapped;
-
- private Location _location;
+ private String attr;
+ private MethodExpression orig;
- private String _qName;
-
public TagMethodExpression()
{
super();
}
- public TagMethodExpression(TagAttribute tagAttribute, MethodExpression methodExpression)
+ public TagMethodExpression(TagAttribute attr, MethodExpression orig)
{
- _location = tagAttribute.getLocation();
- _qName = tagAttribute.getQName();
- _wrapped = methodExpression;
+ this.attr = attr.toString();
+ this.orig = orig;
}
public MethodInfo getMethodInfo(ELContext context)
{
try
{
- return _wrapped.getMethodInfo(context);
+ return this.orig.getMethodInfo(context);
}
catch (PropertyNotFoundException pnfe)
{
- throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
+ throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
}
catch (MethodNotFoundException mnfe)
{
- throw new ContextAwareMethodNotFoundException(getLocation(), getLocalExpressionString(), getQName(), mnfe);
+ throw new MethodNotFoundException(this.attr + ": " + mnfe.getMessage(), mnfe.getCause());
}
catch (ELException e)
{
- throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
- }
- catch (Exception e)
- {
- throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
+ throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
}
}
@@ -90,89 +81,61 @@ public final class TagMethodExpression e
{
try
{
- return _wrapped.invoke(context, params);
+ return this.orig.invoke(context, params);
}
catch (PropertyNotFoundException pnfe)
{
- throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
+ throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
}
catch (MethodNotFoundException mnfe)
{
- throw new ContextAwareMethodNotFoundException(getLocation(), getLocalExpressionString(), getQName(), mnfe);
+ throw new MethodNotFoundException(this.attr + ": " + mnfe.getMessage(), mnfe.getCause());
}
catch (ELException e)
{
- throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
- }
- catch (Exception e)
- {
- throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
- }
- }
-
-
- private String getLocalExpressionString()
- {
- String expressionString = null;
- try
- {
- expressionString = getExpressionString();
- }
- catch (Throwable t)
- {
- //swallo it because it is not important
+ throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
}
- return expressionString;
}
public String getExpressionString()
{
- return _wrapped.getExpressionString();
+ return this.orig.getExpressionString();
}
public boolean equals(Object obj)
{
- return _wrapped.equals(obj);
+ return this.orig.equals(obj);
}
public int hashCode()
{
- return _wrapped.hashCode();
+ return this.orig.hashCode();
}
public boolean isLiteralText()
{
- return _wrapped.isLiteralText();
+ return this.orig.isLiteralText();
}
public void writeExternal(ObjectOutput out) throws IOException
{
- out.writeObject(_wrapped);
- out.writeObject(_location);
- out.writeUTF(_qName);
+ out.writeObject(this.orig);
+ out.writeUTF(this.attr);
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
- _wrapped = (MethodExpression) in.readObject();
- _location = (Location) in.readObject();
- _qName = in.readUTF();
+ this.orig = (MethodExpression) in.readObject();
+ this.attr = in.readUTF();
}
public String toString()
{
- return _location + ": " + _wrapped;
- }
-
- public Location getLocation() {
- return _location;
+ return this.attr + ": " + this.orig;
}
-
- public String getQName() {
- return _qName;
- }
-
- public MethodExpression getWrapped() {
- return _wrapped;
+
+ public MethodExpression getWrapped()
+ {
+ return this.orig;
}
}
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpression.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpression.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpression.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpression.java Mon Sep 12 19:25:49 2011
@@ -29,7 +29,6 @@ import javax.el.PropertyNotFoundExceptio
import javax.el.PropertyNotWritableException;
import javax.el.ValueExpression;
import javax.faces.FacesWrapper;
-import javax.faces.view.Location;
import javax.faces.view.facelets.TagAttribute;
/**
@@ -38,51 +37,44 @@ import javax.faces.view.facelets.TagAttr
* @author Jacob Hookom
* @version $Id: TagValueExpression.java,v 1.7 2008/07/13 19:01:42 rlubke Exp $
*/
-public class TagValueExpression extends ValueExpression implements Externalizable, FacesWrapper<ValueExpression>, ContextAware
+public class TagValueExpression extends ValueExpression implements Externalizable, FacesWrapper<ValueExpression>
{
private static final long serialVersionUID = 1L;
- private ValueExpression _wrapped;
-
- private Location _location;
-
- private String _qName;
+ // orig and attr need to be available in TagValueExpressionUEL
+ ValueExpression orig;
+ String attr;
public TagValueExpression()
{
super();
}
- public TagValueExpression(TagAttribute tagAttribute, ValueExpression valueExpression)
+ public TagValueExpression(TagAttribute attr, ValueExpression orig)
{
- _location = tagAttribute.getLocation();
- _qName = tagAttribute.getQName();
- _wrapped = valueExpression;
+ this.attr = attr.toString();
+ this.orig = orig;
}
public Class<?> getExpectedType()
{
- return _wrapped.getExpectedType();
+ return this.orig.getExpectedType();
}
public Class<?> getType(ELContext context)
{
try
{
- return _wrapped.getType(context);
+ return this.orig.getType(context);
}
catch (PropertyNotFoundException pnfe)
{
- throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
+ throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
}
catch (ELException e)
{
- throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
- }
- catch (Exception e)
- {
- throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
+ throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
}
}
@@ -90,130 +82,93 @@ public class TagValueExpression extends
{
try
{
- return _wrapped.getValue(context);
+ return this.orig.getValue(context);
}
catch (PropertyNotFoundException pnfe)
{
- throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
+ throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
}
catch (ELException e)
{
- throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
- }
- catch (Exception e)
- {
- throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
- }
- }
-
- private String getLocalExpressionString()
- {
- String expressionString = null;
- try
- {
- expressionString = getExpressionString();
- }
- catch (Throwable t)
- {
- //swallo it because it is not important
+ throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
}
- return expressionString;
}
public boolean isReadOnly(ELContext context)
{
try
{
- return _wrapped.isReadOnly(context);
+ return this.orig.isReadOnly(context);
}
catch (PropertyNotFoundException pnfe)
{
- throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
+ throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
}
catch (ELException e)
{
- throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
+ throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
}
- catch (Exception e)
- {
- throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
- }
-
}
public void setValue(ELContext context, Object value)
{
try
{
- _wrapped.setValue(context, value);
+ this.orig.setValue(context, value);
}
catch (PropertyNotFoundException pnfe)
{
- throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
+ throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
}
catch (PropertyNotWritableException pnwe)
{
- throw new ContextAwarePropertyNotWritableException(getLocation(), getLocalExpressionString(), getQName(), pnwe);
+ throw new PropertyNotWritableException(this.attr + ": " + pnwe.getMessage(), pnwe.getCause());
}
catch (ELException e)
{
- throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
- }
- catch (Exception e)
- {
- throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
+ throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
}
}
public boolean equals(Object obj)
{
- return _wrapped.equals(obj);
+ return this.orig.equals(obj);
}
public String getExpressionString()
{
- return _wrapped.getExpressionString();
+ return this.orig.getExpressionString();
}
public int hashCode()
{
- return _wrapped.hashCode();
+ return this.orig.hashCode();
}
public boolean isLiteralText()
{
- return _wrapped.isLiteralText();
+ return this.orig.isLiteralText();
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
- _wrapped = (ValueExpression) in.readObject();
- _location = (Location) in.readObject();
- _qName = in.readUTF();
+ this.orig = (ValueExpression) in.readObject();
+ this.attr = in.readUTF();
}
public void writeExternal(ObjectOutput out) throws IOException
{
- out.writeObject(_wrapped);
- out.writeObject(_location);
- out.writeUTF(_qName);
+ out.writeObject(this.orig);
+ out.writeUTF(this.attr);
}
public String toString()
{
- return _location + ": " + _wrapped;
+ return this.attr + ": " + this.orig;
}
public ValueExpression getWrapped()
{
- return _wrapped;
- }
-
- public Location getLocation() {
- return _location;
- }
-
- public String getQName() {
- return _qName;
+ return orig;
}
}
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java Mon Sep 12 19:25:49 2011
@@ -49,18 +49,15 @@ public class TagValueExpressionUEL exten
{
try
{
- return getWrapped().getValueReference(context);
+ return this.orig.getValueReference(context);
}
catch (PropertyNotFoundException pnfe)
{
- throw new ContextAwarePropertyNotFoundException(getLocation(), getExpressionString(), getQName() , pnfe);
+ throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
}
catch (ELException e)
{
- throw new ContextAwareELException(getLocation(), getExpressionString(), getQName(), e);
- }
- catch (Exception e) {
- throw new ContextAwareELException(getLocation(), getExpressionString(), getQName(), e);
+ throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
}
}
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java Mon Sep 12 19:25:49 2011
@@ -58,6 +58,18 @@ public class FaceletCompositionContextIm
@JSFWebConfigParam(since="2.0.8", defaultValue="noCache", expectedValues="noCache, strict, allowCset, always")
public static final String INIT_PARAM_CACHE_EL_EXPRESSIONS = "org.apache.myfaces.CACHE_EL_EXPRESSIONS";
+ /**
+ * Wrap exception caused by calls to EL expressions, so information like the location, expression string and tag name can be retrieved by
+ * the ExceptionHandler implementation and used to output meaningful information about itself.
+ *
+ * <p>Note in some cases this will wrap the original javax.el.ELException, so the information will not be on the stack trace unless ExceptionHandler
+ * retrieve checking if the exception implements ContextAware interface and calling getWrapped() method.
+ * </p>
+ *
+ */
+ @JSFWebConfigParam(since="2.0.9, 2.1.3" , defaultValue="true", expectedValues="true, false")
+ public static final String INIT_PARAM_WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE = "org.apache.myfaces.WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE";
+
private FacesContext _facesContext;
private FaceletFactory _factory;
@@ -81,6 +93,8 @@ public class FaceletCompositionContextIm
private Boolean _usingPSSOnThisView;
private ELExpressionCacheMode _elExpressionCacheMode;
+
+ private Boolean _isWrapTagExceptionsAsContextAware;
private List<Map<String, UIComponent>> _componentsMarkedForDeletion;
@@ -378,6 +392,17 @@ public class FaceletCompositionContextIm
}
@Override
+ public boolean isWrapTagExceptionsAsContextAware()
+ {
+ if (_isWrapTagExceptionsAsContextAware == null)
+ {
+ _isWrapTagExceptionsAsContextAware = WebConfigParamUtils.getBooleanInitParameter(_facesContext.getExternalContext(),
+ INIT_PARAM_WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE, true);
+ }
+ return _isWrapTagExceptionsAsContextAware;
+ }
+
+ @Override
public void addAttachedObjectHandler(UIComponent compositeComponentParent, AttachedObjectHandler handler)
{
List<AttachedObjectHandler> list = _attachedObjectHandlers.get(compositeComponentParent);
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributeImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributeImpl.java?rev=1169885&r1=1169884&r2=1169885&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributeImpl.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributeImpl.java Mon Sep 12 19:25:49 2011
@@ -32,6 +32,9 @@ import javax.faces.view.facelets.TagAttr
import org.apache.myfaces.util.ExternalSpecifications;
import org.apache.myfaces.view.facelets.AbstractFaceletContext;
import org.apache.myfaces.view.facelets.el.CompositeComponentELUtils;
+import org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression;
+import org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression;
+import org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpressionUEL;
import org.apache.myfaces.view.facelets.el.ELText;
import org.apache.myfaces.view.facelets.el.LocationMethodExpression;
import org.apache.myfaces.view.facelets.el.LocationValueExpression;
@@ -252,7 +255,14 @@ public final class TagAttributeImpl exte
}
}
- methodExpression = new TagMethodExpression(this, methodExpression);
+ if (actx.getFaceletCompositionContext().isWrapTagExceptionsAsContextAware())
+ {
+ methodExpression = new ContextAwareTagMethodExpression(this, methodExpression);
+ }
+ else
+ {
+ methodExpression = new TagMethodExpression(this, methodExpression);
+ }
if (actx.isAllowCacheELExpressions() && !actx.isAnyFaceletsVariableResolved())
{
@@ -436,11 +446,25 @@ public final class TagAttributeImpl exte
if (ExternalSpecifications.isUnifiedELAvailable())
{
- valueExpression = new TagValueExpressionUEL(this, valueExpression);
+ if (actx.getFaceletCompositionContext().isWrapTagExceptionsAsContextAware())
+ {
+ valueExpression = new ContextAwareTagValueExpressionUEL(this, valueExpression);
+ }
+ else
+ {
+ valueExpression = new TagValueExpressionUEL(this, valueExpression);
+ }
}
else
{
- valueExpression = new TagValueExpression(this, valueExpression);
+ if (actx.getFaceletCompositionContext().isWrapTagExceptionsAsContextAware())
+ {
+ valueExpression = new ContextAwareTagValueExpression(this, valueExpression);
+ }
+ else
+ {
+ valueExpression = new TagValueExpression(this, valueExpression);
+ }
}
// if the ValueExpression contains a reference to the current composite
Added: myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/view/facelets/ExceptionNoWrapContextAwareTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/view/facelets/ExceptionNoWrapContextAwareTestCase.java?rev=1169885&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/view/facelets/ExceptionNoWrapContextAwareTestCase.java (added)
+++ myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/view/facelets/ExceptionNoWrapContextAwareTestCase.java Mon Sep 12 19:25:49 2011
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.view.facelets;
+
+import org.apache.myfaces.view.facelets.el.ContextAwareUtils;
+
+public class ExceptionNoWrapContextAwareTestCase extends ExceptionTestCase
+{
+
+ @Override
+ protected void setUpServletObjects() throws Exception
+ {
+ super.setUpServletObjects();
+ servletContext.addInitParameter(
+ ContextAwareUtils.INIT_PARAM_WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE,
+ "false");
+ }
+
+}