org.apache.click.util
Class ErrorPage

java.lang.Object
  extended by org.apache.click.Page
      extended by org.apache.click.util.ErrorPage
All Implemented Interfaces:
Serializable

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 occurred:

 package com.mycorp.util;

 import java.sql.Connection;
 import java.sql.SQLException;
 import org.apache.click.util.ErrorPage;

 public class MyCorpErrorPage extends ErrorPage {

     /**
      * @see Page#onDestroy()
      * /
     public void onDestroy() {
         Exception error = 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:

See Also:
Serialized Form

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<? extends Page> pageClass
          The page class in error.
 
Fields inherited from class org.apache.click.Page
controls, format, forward, headElements, headers, includeControlHeadElements, messages, model, PAGE_ACTION, 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<? extends Page> 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<? extends Page> pageClass)
          Set the page class in error.
 
Methods inherited from class org.apache.click.Page
addControl, addModel, getContentType, getContext, getControls, getFormat, getForward, getHeadElements, getHeaders, getHtmlImports, getMessage, getMessage, getMessages, getModel, getPageImports, getPath, getRedirect, getTemplate, hasControls, hasHeaders, isIncludeControlHeadElements, isStateful, onDestroy, onGet, onPost, onRender, onSecurityCheck, removeControl, setFormat, setForward, setForward, setForward, setHeader, setHeaders, setIncludeControlHeadElements, setPageImports, setPath, setRedirect, setRedirect, 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<? extends Page> 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<? extends Page> getPageClass()
Return the page class in error.

Returns:
the page class in error

setPageClass

public void setPageClass(Class<? extends Page> pageClass)
Set the page class in error.

Parameters:
pageClass - the page class in error