Package org.apache.velocity.tools.view
Class VelocityLayoutServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.apache.velocity.tools.view.VelocityViewServlet
-
- org.apache.velocity.tools.view.VelocityLayoutServlet
-
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
- Direct Known Subclasses:
VelocityLayoutServlet
public class VelocityLayoutServlet extends VelocityViewServlet
Extension of the VelocityViewServlet to perform "two-pass" layout rendering and allow for a customized error screen.- Version:
- $Id$
- Author:
- Nathan Bubna
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_DEFAULT_LAYOUTThe default filename for the servlet's default layoutstatic StringDEFAULT_ERROR_TEMPLATEThe default error template's filename.static StringDEFAULT_LAYOUT_DIRThe default layout directoryprotected StringdefaultLayoutprotected StringerrorTemplatestatic StringKEY_ERROR_CAUSEThe context key that holds theThrowablethat broke the rendering of the requested screen.static StringKEY_ERROR_INVOCATION_EXCEPTIONThe context key that holds theMethodInvocationExceptionthat broke the rendering of the requested screen.static StringKEY_ERROR_STACKTRACEThe context key that holds the stack trace of the error that broke the rendering of the requested screen.static StringKEY_LAYOUTThe context/parameter key used to specify an alternate layout to be used for a request instead of the default layout.static StringKEY_SCREEN_CONTENTThe context key that will hold the content of the screen.protected StringlayoutDirstatic StringPROPERTY_DEFAULT_LAYOUTThe velocity.properties key for specifying the servlet's default layout template's filename.static StringPROPERTY_ERROR_TEMPLATEThe velocity.properties key for specifying the servlet's error template.static StringPROPERTY_LAYOUT_DIRThe velocity.properties key for specifying the relative directory holding layout templates.-
Fields inherited from class org.apache.velocity.tools.view.VelocityViewServlet
BUFFER_OUTPUT_PARAM
-
-
Constructor Summary
Constructors Constructor Description VelocityLayoutServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiderror(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Throwable e)Overrides VelocityViewServlet to display user's custom error templateprotected voidfillContext(org.apache.velocity.context.Context ctx, javax.servlet.http.HttpServletRequest request)Overrides VelocityViewServlet to check the request for an alternate layoutprotected StringfindLayout(javax.servlet.http.HttpServletRequest request)Searches for a non-default layout to be used for this request.voidinit(javax.servlet.ServletConfig config)Initializes Velocity, the view servlet and checks for changes to the initial layout configuration.protected voidmergeTemplate(org.apache.velocity.Template template, org.apache.velocity.context.Context context, javax.servlet.http.HttpServletResponse response)Overrides VelocityViewServlet.mergeTemplate to do a two-pass render for handling layouts-
Methods inherited from class org.apache.velocity.tools.view.VelocityViewServlet
createContext, doGet, doPost, doRequest, findInitParameter, getLog, getTemplate, getTemplate, getVelocityProperty, getVelocityView, handleRequest, manageResourceNotFound, requestCleanup, setContentType, setVelocityView
-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
-
-
-
-
Field Detail
-
PROPERTY_ERROR_TEMPLATE
public static final String PROPERTY_ERROR_TEMPLATE
The velocity.properties key for specifying the servlet's error template.- See Also:
- Constant Field Values
-
PROPERTY_LAYOUT_DIR
public static final String PROPERTY_LAYOUT_DIR
The velocity.properties key for specifying the relative directory holding layout templates.- See Also:
- Constant Field Values
-
PROPERTY_DEFAULT_LAYOUT
public static final String PROPERTY_DEFAULT_LAYOUT
The velocity.properties key for specifying the servlet's default layout template's filename.- See Also:
- Constant Field Values
-
DEFAULT_ERROR_TEMPLATE
public static final String DEFAULT_ERROR_TEMPLATE
The default error template's filename.- See Also:
- Constant Field Values
-
DEFAULT_LAYOUT_DIR
public static final String DEFAULT_LAYOUT_DIR
The default layout directory- See Also:
- Constant Field Values
-
DEFAULT_DEFAULT_LAYOUT
public static final String DEFAULT_DEFAULT_LAYOUT
The default filename for the servlet's default layout- See Also:
- Constant Field Values
-
KEY_SCREEN_CONTENT
public static final String KEY_SCREEN_CONTENT
The context key that will hold the content of the screen. This key ($screen_content) must be present in the layout template for the current screen to be rendered.- See Also:
- Constant Field Values
-
KEY_LAYOUT
public static final String KEY_LAYOUT
The context/parameter key used to specify an alternate layout to be used for a request instead of the default layout.- See Also:
- Constant Field Values
-
KEY_ERROR_CAUSE
public static final String KEY_ERROR_CAUSE
The context key that holds theThrowablethat broke the rendering of the requested screen.- See Also:
- Constant Field Values
-
KEY_ERROR_STACKTRACE
public static final String KEY_ERROR_STACKTRACE
The context key that holds the stack trace of the error that broke the rendering of the requested screen.- See Also:
- Constant Field Values
-
KEY_ERROR_INVOCATION_EXCEPTION
public static final String KEY_ERROR_INVOCATION_EXCEPTION
The context key that holds theMethodInvocationExceptionthat broke the rendering of the requested screen. If this value is placed in the context, then $error_cause will hold the error that this invocation exception is wrapping.- See Also:
- Constant Field Values
-
errorTemplate
protected String errorTemplate
-
layoutDir
protected String layoutDir
-
defaultLayout
protected String defaultLayout
-
-
Method Detail
-
init
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletExceptionInitializes Velocity, the view servlet and checks for changes to the initial layout configuration.- Specified by:
initin interfacejavax.servlet.Servlet- Overrides:
initin classVelocityViewServlet- Parameters:
config- servlet configuration parameters- Throws:
javax.servlet.ServletException
-
fillContext
protected void fillContext(org.apache.velocity.context.Context ctx, javax.servlet.http.HttpServletRequest request)Overrides VelocityViewServlet to check the request for an alternate layout- Overrides:
fillContextin classVelocityViewServlet- Parameters:
ctx- context for this requestrequest- client request
-
findLayout
protected String findLayout(javax.servlet.http.HttpServletRequest request)
Searches for a non-default layout to be used for this request. This implementation checks the request parameters and attributes.
-
mergeTemplate
protected void mergeTemplate(org.apache.velocity.Template template, org.apache.velocity.context.Context context, javax.servlet.http.HttpServletResponse response) throws IOExceptionOverrides VelocityViewServlet.mergeTemplate to do a two-pass render for handling layouts- Overrides:
mergeTemplatein classVelocityViewServlet- Throws:
IOException
-
error
protected void error(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Throwable e)Overrides VelocityViewServlet to display user's custom error template- Overrides:
errorin classVelocityViewServlet- Parameters:
request- original HttpServletRequest from servlet container.response- HttpServletResponse object from servlet container.e- Exception that was thrown by some other part of process.
-
-