net.sf.click.util
Class ErrorPage

java.lang.Object
  extended bynet.sf.click.Page
      extended bynet.sf.click.util.ErrorPage

public class ErrorPage
extends Page

Provides the base error handling Page. The ErrorPage handles any unexpected Exceptions. When the application is not in "production" mode the ErrorPage will provide diagnostic information.

The ErrorPage template "click/error.htm" can be customized to your needs.

Applications which require additional error handling logic must subclass the ErrorPage. For example to rollback a Connection if an SQLException occured:

 package com.mycorp.util;

 import java.sql.Connection;
 import java.sql.SQLException;
 import net.sf.click.util.ErrorPage;

 public class MyCorpErrorPage extends ErrorPage {

     /**
      * @see Page#onDestroy()
      * /
     public void onDestroy() {
         Exception errror = getError();

         if (error instanceof SQLException ||
             error.getCause() instanceof SQLException) {

             Connection connection =
                 ConnectionProviderThreadLocal.getConnection();

             if (connection != null) {
                 try {
                     connection.rollback();
                 }
                 catch (SQLException sqle) {
                 }
                 finally {
                     try {
                         connection.close();
                     }
                     catch (SQLException sqle) {
                     }
                 }
             }
         }
     }
 } 
The ClickServlet sets the following ErrorPage properties in addition to the normal Page properties:

Author:
Malcolm Edgar

Field Summary
protected  Throwable error
          The error causing exception.
protected  String mode
          The application mode:   ["production", "profile", "development", "debug", "trace"].
protected static int NUMB_LINES
          The number of lines to display.
protected  Class pageClass
          The page class in error.
 
Fields inherited from class net.sf.click.Page
controls, format, forward, headers, headersEdited, messages, model, PAGE_MESSAGES, pageImports, path, redirect, stateful, template
 
Constructor Summary
ErrorPage()
           
 
Method Summary
 Throwable getError()
          Return the causing error.
 String getMode()
          Return the application mode: ["production", "profile", "development", debug", "trace"].
 Class getPageClass()
          Return the page class in error.
 void onInit()
          This method initializes the ErrorPage, populating the model with error diagnostic information.
 void setError(Throwable cause)
          Set the causing error.
 void setMode(String value)
          Set the application mode: ["production", "profile", "development", debug", "trace"]

The application mode is added to the model by the onInit() method.

 void setPageClass(Class pageClass)
          Set the page class in error.
 
Methods inherited from class net.sf.click.Page
addControl, addModel, getContentType, getContext, getControls, getFormat, getForward, getHeaders, getHtmlImports, getMessage, getMessage, getMessage, getMessages, getModel, getPageImports, getPath, getRedirect, getTemplate, hasControls, isStateful, onDestroy, onGet, onPost, onRender, onSecurityCheck, removeControl, setFormat, setForward, setForward, setForward, setHeader, setHeaders, setPageImports, setPath, setRedirect, setRedirect, setStateful, setTemplate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUMB_LINES

protected static final int NUMB_LINES
The number of lines to display.

See Also:
Constant Field Values

error

protected Throwable error
The error causing exception.


mode

protected String mode
The application mode:   ["production", "profile", "development", "debug", "trace"].


pageClass

protected Class pageClass
The page class in error.

Constructor Detail

ErrorPage

public ErrorPage()
Method Detail

onInit

public void onInit()
This method initializes the ErrorPage, populating the model with error diagnostic information.

The following values are added to ErrorPage model for rendering by the error page template:

Overrides:
onInit in class Page
See Also:
Page.onInit()

getError

public Throwable getError()
Return the causing error.

Returns:
the causing error

setError

public void setError(Throwable cause)
Set the causing error.

Parameters:
cause - the causing error

getMode

public String getMode()
Return the application mode: ["production", "profile", "development", debug", "trace"].

Returns:
the application mode

setMode

public void setMode(String value)
Set the application mode: ["production", "profile", "development", debug", "trace"]

The application mode is added to the model by the onInit() method. This property is used to determines whether the error page template should display error diagnostic information. The default "error.htm" will display error diagnostic information so long as the application mode is not "production".

Parameters:
value - the application mode.

getPageClass

public Class getPageClass()
Return the page class in error.

Returns:
the page class in error

setPageClass

public void setPageClass(Class pageClass)
Set the page class in error.

Parameters:
pageClass - the page class in error