dev@javaserverfaces.java.net

[REVIEW] Log informational error message if an action listener throws an exception when being invoked

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Wed, 22 Feb 2006 09:32:47 -0800

This change bundle addresses one issue[1] pointed out by Cay Horstmann, and
opens a whole new can of worms (that can being the localization of the API).

[1] http://www.horstmann.com/elvis/hated-error-messages.html

SECTION: Modified Files
----------------------------
M build.xml
 - include the LogStrings.properties in jsf-api.jar

M src/javax/faces/event/MethodExpressionActionListener.java
 - log an informational error message when the MethodExpression
   throws an Exception. The AbortProcessing exception is caught
   by UIViewRoot, but it ignores it to allow the processing of other
   events.


A src/javax/faces/LogStrings.properties
 - thus begins the long journey of localizing the API


SECTION: Diffs
----------------------------
Index: build.xml
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-api/build.xml,v
retrieving revision 1.164
diff -u -r1.164 build.xml
--- build.xml 21 Feb 2006 15:29:12 -0000 1.164
+++ build.xml 22 Feb 2006 17:27:25 -0000
@@ -521,7 +521,7 @@
         <jsf.manifested.jar jarfile="${build.lib.dir}/${name}.jar"
                             basedir="${build.classes.dir}"
                             extension-name="javax.faces"
- includes="**/*.class"/>
+
includes="**/*.class,**/LogStrings.properties"/>
 
     </target>
 
Index: src/javax/faces/event/MethodExpressionActionListener.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-api/src/javax/faces/event/MethodExpressionActionListener.java,v
retrieving revision 1.3
diff -u -r1.3 MethodExpressionActionListener.java
--- src/javax/faces/event/MethodExpressionActionListener.java 5 Dec
2005 16:42:54 -0000 1.3
+++ src/javax/faces/event/MethodExpressionActionListener.java 22 Feb
2006 17:27:26 -0000
@@ -35,6 +35,11 @@
 import javax.faces.context.FacesContext;
 import javax.faces.component.StateHolder;
 
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.io.StringWriter;
+import java.io.PrintWriter;
+
 /**
  * <p><strong>MethodExpressionActionListener</strong> is an {_at_link
ActionListener} that
  * wraps a {_at_link MethodExpression}. When it receives a {_at_link
ActionEvent}, it executes
@@ -44,9 +49,12 @@
 public class MethodExpressionActionListener implements ActionListener,
     StateHolder {
 
+ private static final Logger LOGGER =
+ Logger.getLogger("javax.faces.event", "javax.faces.LogStrings");
+
 
     // ------------------------------------------------------ Instance
Variables
-
+
     private MethodExpression methodExpression = null;
     private boolean isTransient;
 
@@ -68,9 +76,9 @@
     /**
      * @throws NullPointerException {_at_inheritDoc}
      * @throws AbortProcessingException {_at_inheritDoc}
- */
+ */
     public void processAction(ActionEvent actionEvent) throws
AbortProcessingException {
-
+
         if (actionEvent == null) {
             throw new NullPointerException();
         }
@@ -79,6 +87,18 @@
             ELContext elContext = context.getELContext();
             methodExpression.invoke(elContext, new Object[] {actionEvent});
         } catch (ELException ee) {
+ if (LOGGER.isLoggable(Level.SEVERE)) {
+ LOGGER.log(Level.SEVERE,
+ "error.jfev.exception_invoking_processaction",
+ new Object[]{
+ ee.getCause().getClass().getName(),
+ methodExpression.getExpressionString(),
+ actionEvent.getComponent().getId()
+ });
+ StringWriter writer = new StringWriter(1024);
+ ee.getCause().printStackTrace(new PrintWriter(writer));
+ LOGGER.severe(writer.toString());
+ }
             throw new AbortProcessingException(ee.getMessage(),
ee.getCause());
         }
     }


SECTION: New Files
----------------------------
SEE ATTACHMENTS