Class VelocityResult
java.lang.Object
org.apache.struts2.result.StrutsResultSupport
org.apache.struts2.views.velocity.result.VelocityResult
- All Implemented Interfaces:
Serializable
,Result
,StrutsStatics
Using the Servlet container's
JspFactory
, this result mocks a JSP
execution environment and then displays a Velocity template that will be
streamed directly to the servlet output.
This result type takes the following parameters:
- location (default) - the location of the template to process.
- parse - true by default. If set to false, the location param will not be parsed for Ognl expressions.
This result follows the same rules from StrutsResultSupport
.
Example:
<result name="success" type="velocity"> <param name="location">foo.vm</param> </result>
- See Also:
-
Field Summary
Fields inherited from class org.apache.struts2.result.StrutsResultSupport
DEFAULT_PARAM, DEFAULT_URL_ENCODING, parseLocation
Fields inherited from interface org.apache.struts2.StrutsStatics
ACTION_MAPPING, HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.velocity.context.Context
createContext
(VelocityManager velocityManager, ValueStack stack, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String location) Creates the VelocityContext that we'll use to render this page.void
doExecute
(String finalLocation, ActionInvocation invocation) Creates a Velocity context from the action, loads a Velocity template and executes the template.protected String
getContentType
(String templateLocation) Retrieve the content type for this template.protected String
getEncoding
(String templateLocation) Retrieve the encoding for this template.protected org.apache.velocity.Template
getTemplate
(ValueStack stack, org.apache.velocity.app.VelocityEngine velocity, ActionInvocation invocation, String location, String encoding) Given a value stack, a Velocity engine, and an action invocation, this method returns the appropriate Velocity template to render.void
setDefaultEncoding
(String val) void
Methods inherited from class org.apache.struts2.result.StrutsResultSupport
conditionalParse, conditionalParseCollection, execute, getLastFinalLocation, getLocation, setEncode, setLocation, setParse
-
Constructor Details
-
VelocityResult
public VelocityResult() -
VelocityResult
-
-
Method Details
-
setDefaultEncoding
-
setVelocityManager
-
doExecute
Creates a Velocity context from the action, loads a Velocity template and executes the template. Output is written to the servlet output stream.- Specified by:
doExecute
in classStrutsResultSupport
- Parameters:
finalLocation
- the location of the Velocity templateinvocation
- an encapsulation of the action execution state.- Throws:
Exception
- if an error occurs when creating the Velocity context, loading or executing the template or writing output to the servlet response stream.
-
getContentType
Retrieve the content type for this template.People can override this method if they want to provide specific content types for specific templates (eg text/xml).
- Parameters:
templateLocation
- location of template- Returns:
- The content type associated with this template (default "text/html")
-
getEncoding
Retrieve the encoding for this template.People can override this method if they want to provide specific encodings for specific templates.
- Parameters:
templateLocation
- location of template- Returns:
- The encoding associated with this template (defaults to the value of 'struts.i18n.encoding' property)
-
getTemplate
protected org.apache.velocity.Template getTemplate(ValueStack stack, org.apache.velocity.app.VelocityEngine velocity, ActionInvocation invocation, String location, String encoding) throws Exception Given a value stack, a Velocity engine, and an action invocation, this method returns the appropriate Velocity template to render.- Parameters:
stack
- the value stack to resolve the location again (when parse equals true)velocity
- the velocity engine to process the request againstinvocation
- an encapsulation of the action execution state.location
- the location of the templateencoding
- the charset encoding of the template- Returns:
- the template to render
- Throws:
Exception
- when the requested template could not be found
-
createContext
protected org.apache.velocity.context.Context createContext(VelocityManager velocityManager, ValueStack stack, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String location) Creates the VelocityContext that we'll use to render this page.- Parameters:
velocityManager
- a reference to the velocityManager to usestack
- the value stack to resolve the location against (when parse equals true)request
- the servlet requestresponse
- the servlet responselocation
- the name of the template that is being used- Returns:
- the a minted Velocity context.
-