0 Replies Latest reply on Mar 11, 2008 6:48 PM by damianharvey.damianharvey.gmail.com

    Javascript errors in server log

    damianharvey.damianharvey.gmail.com

      I've been battling with Javascript errors from IE today - which is difficult on the Mac.


      After finding this article on Ajaxian I implemented it with Seam + Richfaces. All it does is log client side Javascript errors to your server log. It's not as useful as I thought it would be (still no help with IE's cryptic error messages) but I thought someone might like it.


      This code goes into your page (preferably in your global template where you can take it out before go live. Or not):


      <head>
      <!-- other head stuff -->
      <script>
           onerror= function handleErr(msg,url,l)
           {
                logJavaScriptError(msg, url, l);
           }
      </script>
      </head>
      
      <body>
        <h:form>
          <a:jsFunction action="#{javascriptLogger.error}" name="logJavaScriptError">
            <a:actionparam name="msg" assignTo="#{javascriptLogger.message}"/>
            <a:actionparam name="url" assignTo="#{javascriptLogger.url}"/>
            <a:actionparam name="l" assignTo="#{javascriptLogger.lineNumber}"/>
          </a:jsFunction>
        </h:form>
      


      And a component to log it:


      @Name("javascriptLogger")
      @BypassInterceptors
      public class JavascriptLogger {
        private String message;
        private String url;
        private String lineNumber;
      
        public void setMessage(String message) {
          this.message = message;
        }
      
        public void setUrl(String url) {
          this.url = url;
        }
      
        public void setLineNumber(String lineNumber) {
          this.lineNumber = lineNumber;
        }
      
        public void error() {
          Log log = Logging.getLog(JavascriptLogger.class);
      
          log.error("Javascript error: #0 from URL #1 at Line #2", message, url, lineNumber);
        }
      }
      


      Cheers,


      Damian.