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
Extension of the VelocityViewServlet to perform "two-pass"
layout rendering and allow for a customized error screen.
- Version:
- $Id$
- Author:
- Nathan Bubna
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default filename for the servlet's default layoutstatic final StringThe default error template's filename.static final StringThe default layout directoryprotected Stringprotected Stringstatic final StringThe context key that holds theThrowablethat broke the rendering of the requested screen.static final StringThe context key that holds theMethodInvocationExceptionthat broke the rendering of the requested screen.static final StringThe context key that holds the stack trace of the error that broke the rendering of the requested screen.static final StringThe context/parameter key used to specify an alternate layout to be used for a request instead of the default layout.static final StringThe context key that will hold the content of the screen.protected Stringstatic final StringThe velocity.properties key for specifying the servlet's default layout template's filename.static final StringThe velocity.properties key for specifying whether dynamic layout change is allowedstatic final StringThe velocity.properties key for specifying the servlet's error template.static final StringThe velocity.properties key for specifying the relative directory holding layout templates.Fields inherited from class VelocityViewServlet
BUFFER_OUTPUT_PARAM -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Overrides VelocityViewServlet.mergeTemplate to do a two-pass render for handling layoutsMethods inherited from class VelocityViewServlet
createContext, doGet, doPost, doRequest, findInitParameter, getLog, getOutputWriter, getTemplate, getTemplate, getVelocityProperty, getVelocityView, handleRequest, initRequest, manageResourceNotFound, mergeTemplate, requestCleanup, setContentType, setVelocityViewMethods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, serviceMethods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Field Details
-
PROPERTY_ERROR_TEMPLATE
The velocity.properties key for specifying the servlet's error template.- See Also:
-
PROPERTY_LAYOUT_DIR
The velocity.properties key for specifying the relative directory holding layout templates.- See Also:
-
PROPERTY_DEFAULT_LAYOUT
The velocity.properties key for specifying the servlet's default layout template's filename.- See Also:
-
DEFAULT_ERROR_TEMPLATE
-
DEFAULT_LAYOUT_DIR
-
DEFAULT_DEFAULT_LAYOUT
The default filename for the servlet's default layout- See Also:
-
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:
-
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:
-
KEY_ERROR_CAUSE
-
KEY_ERROR_STACKTRACE
The context key that holds the stack trace of the error that broke the rendering of the requested screen.- See Also:
-
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:
-
PROPERTY_DYNAMIC_LAYOUT
The velocity.properties key for specifying whether dynamic layout change is allowed- See Also:
-
errorTemplate
-
layoutDir
-
defaultLayout
-
-
Constructor Details
-
VelocityLayoutServlet
public VelocityLayoutServlet()
-
-
Method Details
-
init
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException Initializes 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
Searches for a non-default layout to be used for this request. This implementation checks the request parameters and attributes.- Parameters:
request- servlet request- Returns:
- layout name or null
-
mergeTemplate
protected void mergeTemplate(org.apache.velocity.Template template, org.apache.velocity.context.Context context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException Overrides VelocityViewServlet.mergeTemplate to do a two-pass render for handling layouts- Overrides:
mergeTemplatein classVelocityViewServlet- Parameters:
template-Templateobjectcontext- Velocity contextrequest- servlet requestresponse- servlet response- 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- servlet requestresponse- servlet responsee- thrown error
-