tiles-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fitt, Arthur" <af...@ptc.com>
Subject How to set the value of an attribute to the value of a bean property.
Date Thu, 28 Feb 2008 16:38:16 GMT
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.


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. 

      ignore="true" flush="false" 

   public class ToolbarPreparer extends ViewPreparerSupport {

       public void execute(TilesRequestContext tilesContext, 
                 AttributeContext attributeContext) throws
PreparerException {

           ViewBeanManager viewBeanManager = (ViewBeanManager)
           String toolbarUiPath = viewBeanManager.getToolbarUiPath();
           attributeContext.putAttribute("toolbar", new

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) {

        if (attr == null) {
            if (name != null) {
                throw new TilesException("Attribute '" + name + "' not
            } else {
                throw new TilesException("No attribute name or value has
been provided.");

Please let me know if there is an easier way to do this and/or my fix is

View raw message