You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2007/08/02 10:15:58 UTC

svn commit: r562042 - in /myfaces/core/branches/1_2_1/api/src/main: java/javax/faces/webapp/_ErrorPageWriter.java resources/rsc/facelet-dev-debug.xml resources/rsc/facelet-dev-error.xml

Author: mmarinschek
Date: Thu Aug  2 01:15:55 2007
New Revision: 562042

URL: http://svn.apache.org/viewvc?view=rev&rev=562042
Log:
https://issues.apache.org/jira/browse/MYFACES-1688: Extended Error Handling in MyFaces, thanks to Sorin Silaghi

Modified:
    myfaces/core/branches/1_2_1/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java
    myfaces/core/branches/1_2_1/api/src/main/resources/rsc/facelet-dev-debug.xml
    myfaces/core/branches/1_2_1/api/src/main/resources/rsc/facelet-dev-error.xml

Modified: myfaces/core/branches/1_2_1/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1_2_1/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java?view=diff&rev=562042&r1=562041&r2=562042
==============================================================================
--- myfaces/core/branches/1_2_1/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java (original)
+++ myfaces/core/branches/1_2_1/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java Thu Aug  2 01:15:55 2007
@@ -21,11 +21,11 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import javax.faces.context.FacesContext;
+import javax.faces.context.ExternalContext;
+import javax.faces.component.UIComponent;
 import javax.el.Expression;
 import javax.el.ValueExpression;
-import javax.faces.component.UIComponent;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletResponse;
 import java.beans.BeanInfo;
@@ -35,6 +35,8 @@
 import java.lang.reflect.Method;
 import java.text.DateFormat;
 import java.util.*;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 
 /**
  * @author Jacob Hookom (ICLA with ASF filed)
@@ -86,6 +88,34 @@
         return str.split("@@");
     }
 
+    private static ArrayList getErrorId(Exception e){
+        String message = e.getMessage();
+        ArrayList list = new ArrayList();
+        Pattern pattern = Pattern.compile(".*?\\Q,Id:\\E\\s*(\\S+)\\s*\\].*?");
+        Matcher matcher = pattern.matcher(message);
+
+        while (matcher.find()){
+            list.add(matcher.group(1));
+        }
+        if (list.size()>0) return list;
+        return null;
+    }
+
+    public static void writeCause(Writer writer, Throwable ex) throws IOException {
+        String msg = ex.getMessage();
+        while (ex.getCause()!=null){
+            ex=ex.getCause();
+            if (ex.getMessage()!=null) msg = ex.getMessage();
+        }
+
+        if (msg != null) {
+            msg =ex.getClass().getName() + " - " + msg;
+            writer.write(msg.replaceAll("<", TS));
+        } else {
+            writer.write(ex.getClass().getName());
+        }
+    }
+    
     public static void debugHtml(Writer writer, FacesContext faces, Exception e) throws IOException {
         init();
         Date now = new Date();
@@ -102,9 +132,11 @@
             } else if ("now".equals(ERROR_PARTS[i])) {
                 writer.write(DateFormat.getDateTimeInstance().format(now));
             } else if ("tree".equals(ERROR_PARTS[i])) {
-                writeComponent(writer, faces.getViewRoot());
+                writeComponent(writer, faces.getViewRoot(), getErrorId(e));
             } else if ("vars".equals(ERROR_PARTS[i])) {
                 writeVariables(writer, faces);
+            } else if ("cause".equals(ERROR_PARTS[i])) {
+                writeCause(writer, e);
             } else {
                 writer.write(ERROR_PARTS[i]);
             }
@@ -128,7 +160,7 @@
             } else if ("now".equals(DEBUG_PARTS[i])) {
                 writer.write(DateFormat.getDateTimeInstance().format(now));
             } else if ("tree".equals(DEBUG_PARTS[i])) {
-                writeComponent(writer, faces.getViewRoot());
+                writeComponent(writer, faces.getViewRoot(), null);
             } else if ("vars".equals(DEBUG_PARTS[i])) {
                 writeVariables(writer, faces);
             } else {
@@ -175,11 +207,19 @@
         writer.write("</tbody></table>");
     }
 
-    private static void writeComponent(Writer writer, UIComponent c) throws IOException {
+    private static void writeComponent(Writer writer, UIComponent c, List highlightId) throws IOException {
         writer.write("<dl><dt");
         if (isText(c)) {
             writer.write(" class=\"uicText\"");
         }
+        if (highlightId != null){
+            if ((highlightId.size() > 0) && (highlightId.get(0).equals(c.getId()))){
+                highlightId.remove(0);
+                if (highlightId.size()==0){
+                    writer.write(" class=\"highlightComponent\"");
+                }
+            }
+        }
         writer.write(">");
 
         boolean hasChildren = c.getChildCount() > 0 || c.getFacets().size() > 0;
@@ -195,14 +235,14 @@
                     writer.write("<span>");
                     writer.write((String) entry.getKey());
                     writer.write("</span>");
-                    writeComponent(writer, (UIComponent) entry.getValue());
+                    writeComponent(writer, (UIComponent) entry.getValue(), highlightId);
                     writer.write("</dd>");
                 }
             }
             if (c.getChildCount() > 0) {
                 for (Iterator itr = c.getChildren().iterator(); itr.hasNext(); ) {
                     writer.write("<dd>");
-                    writeComponent(writer, (UIComponent) itr.next());
+                    writeComponent(writer, (UIComponent) itr.next(), highlightId);
                     writer.write("</dd>");
                 }
             }

Modified: myfaces/core/branches/1_2_1/api/src/main/resources/rsc/facelet-dev-debug.xml
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1_2_1/api/src/main/resources/rsc/facelet-dev-debug.xml?view=diff&rev=562042&r1=562041&r2=562042
==============================================================================
--- myfaces/core/branches/1_2_1/api/src/main/resources/rsc/facelet-dev-debug.xml (original)
+++ myfaces/core/branches/1_2_1/api/src/main/resources/rsc/facelet-dev-debug.xml Thu Aug  2 01:15:55 2007
@@ -17,6 +17,7 @@
 #tree dd { margin-top: 2px; margin-bottom: 2px; }
 #tree dt { border: 1px solid #DDD; padding: 4px; border-left: 2px solid #666; font-family: "Courier New", Courier, mono; font-size: small; }
 .uicText { color: #999;  }
+.highlightComponent { color: #FFFFFF; background-color: #FF0000;  }
 table { border: 1px solid #CCC; border-collapse: collapse; border-spacing: 0px; width: 100%; text-align: left; }
 td { border: 1px solid #CCC; }
 thead tr th { padding: 2px; color: #030; background-color: #F9F9F9; }
@@ -48,6 +49,7 @@
 <div id="tree" class="grayBox"><code>@@tree@@</code></div>
 <h2><a href="#" onclick="toggle('vars'); return false;"><span id="varsOff">+</span><span id="varsOn" style="display: none;">-</span> Scoped Variables</a></h2>
 <div id="vars">@@vars@@</div>
-<div class="grayBox" style="text-align: right; color: #666;">@@now@@ - Generated by Facelets</div>
+<div class="grayBox" style="text-align: right; color: #666;">@@now@@ - Generated by MyFaces - for information on disabling or modifying this error-page, see <a
+href="http://wiki.apache.org/myfaces/Handling_Server_Errors">Server error handling</a></div>
 </body>
 </html>

Modified: myfaces/core/branches/1_2_1/api/src/main/resources/rsc/facelet-dev-error.xml
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1_2_1/api/src/main/resources/rsc/facelet-dev-error.xml?view=diff&rev=562042&r1=562041&r2=562042
==============================================================================
--- myfaces/core/branches/1_2_1/api/src/main/resources/rsc/facelet-dev-error.xml (original)
+++ myfaces/core/branches/1_2_1/api/src/main/resources/rsc/facelet-dev-error.xml Thu Aug  2 01:15:55 2007
@@ -17,6 +17,7 @@
 #tree dd { margin-top: 2px; margin-bottom: 2px; }
 #tree dt { border: 1px solid #DDD; padding: 4px; border-left: 2px solid #666; font-family: "Courier New", Courier, mono; font-size: small; }
 .uicText { color: #999;  }
+.highlightComponent { color: #FFFFFF; background-color: #FF0000;  }
 table { border: 1px solid #CCC; border-collapse: collapse; border-spacing: 0px; width: 100%; text-align: left; }
 td { border: 1px solid #CCC; }
 thead tr th { padding: 2px; color: #030; background-color: #F9F9F9; }
@@ -43,13 +44,14 @@
 </head>
 <body>
 <h1>An Error Occurred:</h1>
-<div id="error" class="grayBox" style="border: 1px solid #900;">@@message@@</div>
+<div id="error" class="grayBox" style="border: 1px solid #900;">@@message@@<br/><br/>Caused by:<br/>@@cause@@</div>
 <h2><a href="#" onclick="toggle('trace'); return false;"><span id="traceOff">+</span><span id="traceOn" style="display: none;">-</span> Stack Trace</a></h2>
 <div id="trace" class="grayBox"><pre><code>@@trace@@</code></pre></div>
 <h2><a href="#" onclick="toggle('tree'); return false;"><span id="treeOff">+</span><span id="treeOn" style="display: none;">-</span> Component Tree</a></h2>
 <div id="tree" class="grayBox"><code>@@tree@@</code></div>
 <h2><a href="#" onclick="toggle('vars'); return false;"><span id="varsOff">+</span><span id="varsOn" style="display: none;">-</span> Scoped Variables</a></h2>
 <div id="vars">@@vars@@</div>
-<div class="grayBox" style="text-align: right; color: #666;">@@now@@ - Generated by Facelets</div>
+<div class="grayBox" style="text-align: right; color: #666;">@@now@@ - Generated by MyFaces - for information on disabling or modifying this error-page, see <a
+href="http://wiki.apache.org/myfaces/Handling_Server_Errors">Disabling error handling in MyFaces</a></div>
 </body>
 </html>