|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Using variable in decoratorsHi all,
I want to use to a dynamic variable, such as ${template}, in my decorators.xml. Can I do it? example: <decorators defaultdir="/decorators"> <decorator name="default" page="${template}/default.jsp"> <pattern>/*</pattern> </decorator> </decorators> Regards! Mauri. |
|
|
Re: Using variable in decoratorsHi Maurif
The decorators.xml configuration loader does not support variables. However you can extends SiteMesh by adding your own DecoratorMapper to the stack that will do the variable substitution. Here is a really crude implementation - but enough to get the point over. public class MyVariableSubstitutingDecoratorMapper extends AbstractDecoratorMapper { public Decorator getNamedDecorator(HttpServletRequest request, String name) { Decorator decorator = super.getNamedDecorator(request, name)); if (decorator.getPage().contains("${template}")) { // replace decorator with a new page location. String newPage = decorator.getPage().replace("${template}", "something"); decorator new DefaultDecorator(original.getName(), newPage, new HashMap()); } return decorator; } } To get SiteMesh to use this, you need to add it to WEB-INF/sitemesh.xml. (If you do not have this file, you can extract it from sitemesh.jar, named sitemesh-default.xml, or grab it here: http://fisheye5.cenqua.com/browse/~raw,r=1.5/sitemesh/src/java/com/opensymphony/module/sitemesh/factory/sitemesh-default.xml). It should be inserted just before the ConfigDecoratorMapper. <sitemesh> ... <decorator-mappers> ... the other mappers ... <mapper class="com.yourpackage.MyVariableSubstitutingDecoratorMapper"/> <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper"> ... </mapper> </decorator-mappers> </sitemesh> Hope that helps. -Joe On Tue, May 12, 2009 at 3:16 PM, Mauriff <mauriff@...> wrote:
|
| Free embeddable forum powered by Nabble | Forum Help |