myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmarinsc...@apache.org
Subject svn commit: r562036 - in /myfaces/core/trunk/api/src/main: java/javax/faces/webapp/_ErrorPageWriter.java resources/META-INF/rsc/facelet-dev-debug.xml resources/META-INF/rsc/facelet-dev-error.xml
Date Thu, 02 Aug 2007 07:52:46 GMT
Author: mmarinschek
Date: Thu Aug  2 00:52:44 2007
New Revision: 562036

URL: http://svn.apache.org/viewvc?view=rev&rev=562036
Log:
https://issues.apache.org/jira/browse/MYFACES-1688: Highlighting of component on error page.
Thanks to Sorin Silaghi for this excellent productivity patch.

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java
    myfaces/core/trunk/api/src/main/resources/META-INF/rsc/facelet-dev-debug.xml
    myfaces/core/trunk/api/src/main/resources/META-INF/rsc/facelet-dev-error.xml

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java?view=diff&rev=562036&r1=562035&r2=562036
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/webapp/_ErrorPageWriter.java Thu Aug
 2 00:52:44 2007
@@ -35,13 +35,9 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.InvocationTargetException;
 import java.text.DateFormat;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
+import java.util.*;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.ExternalContext;
@@ -100,6 +96,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();
@@ -116,9 +140,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]);
             }
@@ -142,7 +168,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 {
@@ -189,11 +215,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;
@@ -209,14 +243,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/trunk/api/src/main/resources/META-INF/rsc/facelet-dev-debug.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/resources/META-INF/rsc/facelet-dev-debug.xml?view=diff&rev=562036&r1=562035&r2=562036
==============================================================================
--- myfaces/core/trunk/api/src/main/resources/META-INF/rsc/facelet-dev-debug.xml (original)
+++ myfaces/core/trunk/api/src/main/resources/META-INF/rsc/facelet-dev-debug.xml Thu Aug 
2 00:52:44 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; }

Modified: myfaces/core/trunk/api/src/main/resources/META-INF/rsc/facelet-dev-error.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/resources/META-INF/rsc/facelet-dev-error.xml?view=diff&rev=562036&r1=562035&r2=562036
==============================================================================
--- myfaces/core/trunk/api/src/main/resources/META-INF/rsc/facelet-dev-error.xml (original)
+++ myfaces/core/trunk/api/src/main/resources/META-INF/rsc/facelet-dev-error.xml Thu Aug 
2 00:52:44 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,7 +44,7 @@
 </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>



Mime
View raw message