public class TilesTool extends ImportSupport
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:
<tool>
<key>tiles</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.TilesTool</class>
</tool>
This tool should only be used in the request scope.
ImportSupport.ImportResponseWrapper, ImportSupport.SafeClosingHttpURLConnectionReader| Modifier and Type | Field and Description |
|---|---|
(package private) static java.lang.String |
APPLICATION_SCOPE |
protected java.util.Stack |
contextStack
A stack to hold ComponentContexts while nested tile-definitions
are rendered.
|
protected static org.apache.commons.logging.Log |
LOG |
protected boolean |
methodExceptionHandlerPresent
Indicates if there is a MethodExceptionEventHandler present
|
(package private) static java.lang.String |
PAGE_SCOPE |
(package private) static java.lang.String |
REQUEST_SCOPE |
(package private) static java.lang.String |
SESSION_SCOPE |
protected org.apache.velocity.context.Context |
velocityContext |
application, DEFAULT_ENCODING, request, response, VALID_SCHEME_CHARS| Constructor and Description |
|---|
TilesTool()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.String |
doInsert(org.apache.struts.tiles.ComponentContext subCompContext,
java.lang.String page,
java.lang.String role,
org.apache.struts.tiles.Controller controller)
An extension of the other two doInsert functions
|
protected java.lang.String |
doInsert(java.util.Map attributes,
java.lang.String page,
java.lang.String role,
org.apache.struts.tiles.Controller controller)
Use this if there is a nested tile.
|
protected java.lang.String |
doInsert(java.lang.String page,
java.lang.String role,
org.apache.struts.tiles.Controller controller)
Use this if there is no nested tile.
|
java.lang.String |
get(java.lang.Object obj)
A generic tiles insert function.
|
java.lang.Object |
getAttribute(java.lang.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(java.lang.String name)
Imports the named attribute-value from the current tiles-context into the
current Velocity context.
|
void |
importAttribute(java.lang.String name,
java.lang.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(java.lang.String scope)
Imports all attributes in the current tiles-context into the named
context ("page", "request", "session", or "application").
|
void |
init(java.lang.Object obj)
Initializes this tool.
|
protected void |
popTilesContext()
Pops the tiles sub-context off the context-stack after the lower level
tiles have been rendered.
|
protected java.lang.String |
processAsDefinitionOrURL(java.lang.String name)
Try to process name as a definition, or as an URL if not found.
|
protected java.lang.String |
processDefinition(org.apache.struts.tiles.ComponentDefinition definition)
End of Process for definition.
|
protected java.lang.String |
processObjectValue(java.lang.Object value)
Process an object retrieved as a bean or attribute.
|
protected java.lang.String |
processTypedAttribute(org.apache.struts.tiles.AttributeDefinition value)
Process typed attribute according to its type.
|
protected java.lang.String |
processUrl(java.lang.String url)
Processes an url
|
protected void |
pushTilesContext()
pushes the current tiles context onto the context-stack.
|
acquireReader, acquireString, getContentTypeAttribute, isAbsoluteUrl, stripSessionprotected static final org.apache.commons.logging.Log LOG
static final java.lang.String PAGE_SCOPE
static final java.lang.String REQUEST_SCOPE
static final java.lang.String SESSION_SCOPE
static final java.lang.String APPLICATION_SCOPE
protected org.apache.velocity.context.Context velocityContext
protected java.util.Stack contextStack
protected boolean methodExceptionHandlerPresent
public TilesTool()
public void init(java.lang.Object obj)
obj - the current ViewContextjava.lang.IllegalArgumentException - if the param is not a ViewContextpublic java.lang.String get(java.lang.Object obj)
throws java.lang.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)java.lang.Exception - on failurepublic java.lang.Object getAttribute(java.lang.String name)
This is functionally equivalent to
<tiles:getAsString name="foo" />.
name - the name of the tiles-attribute to fetchpublic void importAttribute(java.lang.String name)
This is functionally equivalent to
<tiles:importAttribute name="foo" />
name - the name of the tiles-attribute to importpublic void importAttribute(java.lang.String name,
java.lang.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(java.lang.String scope)
This is functionally equivalent to
<tiles:importAttribute scope="scopeValue" />.
scope - the named context scope to put the attributes into.protected java.lang.String processObjectValue(java.lang.Object value)
throws java.lang.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.java.lang.Exception - - Throws by underlying nested call to
processDefinitionName()protected java.lang.String processTypedAttribute(org.apache.struts.tiles.AttributeDefinition value)
throws java.lang.Exception
value - Typed attribute to process.java.lang.Exception - - Throws by underlying nested call to processDefinitionName()protected java.lang.String processAsDefinitionOrURL(java.lang.String name)
throws java.lang.Exception
name - Name to process.java.lang.Exceptionprotected java.lang.String processDefinition(org.apache.struts.tiles.ComponentDefinition definition)
throws java.lang.Exception
definition - Definition to process.java.lang.Exception - from InstantiationException Can't create requested controllerprotected java.lang.String processUrl(java.lang.String url)
throws java.lang.Exception
url - the URI to process.java.lang.Exceptionprotected java.lang.String doInsert(java.lang.String page,
java.lang.String role,
org.apache.struts.tiles.Controller controller)
throws java.lang.Exception
page - the page to process.role - possible user-rolecontroller - possible tiles-controllerjava.lang.Exceptionprotected java.lang.String doInsert(java.util.Map attributes,
java.lang.String page,
java.lang.String role,
org.apache.struts.tiles.Controller controller)
throws java.lang.Exception
attributes - attributes for the sub-contextpage - the page to process.role - possible user-rolecontroller - possible tiles-controllerjava.lang.Exceptionprotected java.lang.String doInsert(org.apache.struts.tiles.ComponentContext subCompContext,
java.lang.String page,
java.lang.String role,
org.apache.struts.tiles.Controller controller)
throws java.lang.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-controllerjava.lang.Exceptionprotected 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 (c) 2003-2007 Apache Software Foundation