I'm converting from using stuts-tiles in JSF 1.1 to tiles 2 and JSF 1.2.
Most everything is working since a used the code for the
TilesViewHandler I found on the Shale page.
http://issues.apache.org/struts/browse/SHALE-302. I am using tiles
version 2.0.5.
In struts-tiles I was able to embed a template whose URI was the value
of a java property using the following syntax.
<tiles:insert
beanName="ViewBeanManager"
beanProperty="toolbarUiPath"
beanScope="session"
ignore="true"
flush="false"
/>
In this case the toobarUiPath property contains a String with the URI to
the template to insert. For example "/pages/standardToolbar.jsp"
I have been unable to get this to work in tiles 2.
>From reading through the documentation and the archives of the user
group I thought the answer was to use a Preparer. I wrote
ToolbarPreparer and used the tags below.
<tiles:insertAttribute
value="toolbar"
preparer="com.netregulus.ui.core.tiles.ToolbarPreparer"
ignore="true" flush="false"
/>
public class ToolbarPreparer extends ViewPreparerSupport {
@Override
public void execute(TilesRequestContext tilesContext,
AttributeContext attributeContext) throws
PreparerException {
ViewBeanManager viewBeanManager = (ViewBeanManager)
tilesContext.getSessionScope().get("ViewBeanManager");
String toolbarUiPath = viewBeanManager.getToolbarUiPath();
attributeContext.putAttribute("toolbar", new
Attribute(toolbarUiPath));
}
}
The preparer put the attribute into the attributeContext but the
attributeContext isn't accessed in the InsertAttributeTag.render()
method. This could be fixed by modifying the render() method as follows:
protected void render() throws JspException, TilesException,
IOException {
Attribute attr = (Attribute) value;
if (attr == null && evaluatingContext != null) {
attr = evaluatingContext.getAttribute(name);
// I'm not sure if the attributeContext should be checked
before or
// after the evaluatingContext.
if (attr == null) {
attr = attributeContext.getAttribute(name);
}
}
if (attr == null && ignore) {
return;
}
if (attr == null) {
if (name != null) {
throw new TilesException("Attribute '" + name + "' not
found.");
} else {
throw new TilesException("No attribute name or value has
been provided.");
}
}
render(attr);
}
Please let me know if there is an easier way to do this and/or my fix is
correct.