@DefaultKey(value="tiles") @ValidScope(value="request") public class TilesTool extends ImportSupport
The TilesTool is used to interact with the Struts-Tiles framework that is part of Struts 1.
Template example(s): <!-- insert a tile --> $tiles.myTileDefinition <!-- get named attribute value from the current tiles-context --> $tiles.getAttribute("myTileAttribute") <!-- import all attributes of the current tiles-context into the velocity-context. --> $tiles.importAttributes() Toolbox configuration: <tools> <toolbox scope="request"> <tool class="org.apache.velocity.tools.struts.TilesTool"/> </toolbox> </tools>
This tool may only be used in the request scope.
ImportSupport.ImportResponseWrapper, ImportSupport.SafeClosingHttpURLConnectionReader
Modifier and Type | Field and Description |
---|---|
protected boolean |
catchExceptions
Indicates if there is a MethodExceptionEventHandler present
|
protected Stack |
contextStack
A stack to hold ComponentContexts while nested tile-definitions
are rendered.
|
protected org.apache.velocity.context.Context |
velocityContext |
application, DEFAULT_ENCODING, LOG, request, response, VALID_SCHEME_CHARS
Constructor and Description |
---|
TilesTool() |
Modifier and Type | Method and Description |
---|---|
protected String |
doInsert(org.apache.struts.tiles.ComponentContext subCompContext,
String page,
String role,
org.apache.struts.tiles.Controller controller)
An extension of the other two doInsert functions
|
protected String |
doInsert(Map attributes,
String page,
String role,
org.apache.struts.tiles.Controller controller)
Use this if there is a nested tile.
|
protected String |
doInsert(String page,
String role,
org.apache.struts.tiles.Controller controller)
Use this if there is no nested tile.
|
String |
get(Object obj)
A generic tiles insert function.
|
Object |
getAttribute(String name)
Fetches a named attribute-value from the current tiles-context.
|
protected org.apache.struts.tiles.ComponentContext |
getCurrentContext()
Retrieve the current tiles component context.
|
void |
importAttribute(String name)
Imports the named attribute-value from the current tiles-context into the
current Velocity context.
|
void |
importAttribute(String name,
String scope)
Imports the named attribute-value from the current tiles-context into the
named context ("page", "request", "session", or "application").
|
void |
importAttributes()
Imports all attributes in the current tiles-context into the
current velocity-context.
|
void |
importAttributes(String scope)
Imports all attributes in the current tiles-context into the named
context ("page", "request", "session", or "application").
|
void |
init(Object obj)
Deprecated.
|
protected void |
popTilesContext()
Pops the tiles sub-context off the context-stack after the lower level
tiles have been rendered.
|
protected String |
processAsDefinitionOrURL(String name)
Try to process name as a definition, or as an URL if not found.
|
protected String |
processDefinition(org.apache.struts.tiles.ComponentDefinition definition)
End of Process for definition.
|
protected String |
processObjectValue(Object value)
Process an object retrieved as a bean or attribute.
|
protected String |
processTypedAttribute(org.apache.struts.tiles.AttributeDefinition value)
Process typed attribute according to its type.
|
protected String |
processUrl(String url)
Processes an url
|
protected void |
pushTilesContext()
pushes the current tiles context onto the context-stack.
|
void |
setCatchExceptions(boolean catchExceptions) |
void |
setVelocityContext(org.apache.velocity.context.Context context)
Initializes this tool.
|
acquireReader, acquireString, getContentTypeAttribute, isAbsoluteUrl, setLog, setRequest, setResponse, setServletContext, stripSession
protected org.apache.velocity.context.Context velocityContext
protected Stack contextStack
protected boolean catchExceptions
@Deprecated public void init(Object obj)
public void setVelocityContext(org.apache.velocity.context.Context context)
context
- the current Context
IllegalArgumentException
- if the param is not a Context
public void setCatchExceptions(boolean catchExceptions)
public String get(Object obj) throws Exception
This is functionally equivalent to
<tiles:insert attribute="foo" />
.
obj
- Can be any of the following:
AttributeDefinition,
tile-definition name,
tile-attribute name,
regular uri.
(checked in that order)Exception
- on failurepublic Object getAttribute(String name)
This is functionally equivalent to
<tiles:getAsString name="foo" />
.
name
- the name of the tiles-attribute to fetchpublic void importAttribute(String name)
This is functionally equivalent to
<tiles:importAttribute name="foo" />
name
- the name of the tiles-attribute to importpublic void importAttribute(String name, String scope)
This is functionally equivalent to
<tiles:importAttribute name="foo" scope="scopeValue" />
name
- the name of the tiles-attribute to importscope
- the named context scope to put the attribute into.public void importAttributes()
This is functionally equivalent to
<tiles:importAttribute />
.
public void importAttributes(String scope)
This is functionally equivalent to
<tiles:importAttribute scope="scopeValue" />
.
scope
- the named context scope to put the attributes into.protected String processObjectValue(Object value) throws Exception
value
- - Object can be a typed attribute, a String, or anything
else. If typed attribute, use associated type. Otherwise, apply
toString() on object, and use returned string as a name.Exception
- - Throws by underlying nested call to
processDefinitionName()protected String processTypedAttribute(org.apache.struts.tiles.AttributeDefinition value) throws Exception
value
- Typed attribute to process.Exception
- - Throws by underlying nested call to processDefinitionName()protected String processAsDefinitionOrURL(String name) throws Exception
name
- Name to process.Exception
protected String processDefinition(org.apache.struts.tiles.ComponentDefinition definition) throws Exception
definition
- Definition to process.Exception
- from InstantiationException Can't create requested controllerprotected String processUrl(String url) throws Exception
url
- the URI to process.Exception
protected String doInsert(String page, String role, org.apache.struts.tiles.Controller controller) throws Exception
page
- the page to process.role
- possible user-rolecontroller
- possible tiles-controllerException
protected String doInsert(Map attributes, String page, String role, org.apache.struts.tiles.Controller controller) throws Exception
attributes
- attributes for the sub-contextpage
- the page to process.role
- possible user-rolecontroller
- possible tiles-controllerException
protected String doInsert(org.apache.struts.tiles.ComponentContext subCompContext, String page, String role, org.apache.struts.tiles.Controller controller) throws Exception
subCompContext
- the sub-context to set in scope when the
template is rendered.page
- the page to process.role
- possible user-rolecontroller
- possible tiles-controllerException
protected org.apache.struts.tiles.ComponentContext getCurrentContext()
protected void pushTilesContext()
pushes the current tiles context onto the context-stack. preserving the context is necessary so that a sub-context can be put into request scope and lower level tiles can be rendered
protected void popTilesContext()
Copyright © 2002–2014 Apache Software Foundation. All rights reserved.