Thanks for the help Antonio.  I'm not quite sure how I can get the title.
I'ved used the Spring framework to inject my body jsp path based on the
Action path.  I'm using REST style urls, so I have a
<controller>/<action>(/<other args>)* syntax on all my calls.  Getting the
body dynamially injected only took the following.  However, I don't want my
title's based on interception as that's part of the view.  Its not possible
to "bubble" attributes from includes up to their parent?

Thanks,
Todd



public class AutoTilesView extends TilesView {

    private static final String BODY_KEY = "body";
    private static final String PREFIX = "/WEB-INF/views/";
    private static final String SUFFIX = ".jsp";

    /* (non-Javadoc)
     * @see
org.springframework.web.servlet.view.tiles2.TilesView#renderMergedOutputModel(java.util.Map,
javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
     */
    @Override
    protected void renderMergedOutputModel(Map<String, Object> model,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //get the body tag and insert it into the context before calling the
super.

        ServletContext servletContext = getServletContext();
        TilesContainer container = ServletUtil.getContainer(servletContext);

        if (container == null) {
            throw new ServletException("Tiles container is not initialized.
" +
                    "Have you added a TilesConfigurer to your web
application context?");
        }

        AttributeContext attributeContext =
container.getAttributeContext(request,
                response);

        StringBuilder builder = new StringBuilder();
        builder.append(PREFIX);
        builder.append(this.getUrl());
        builder.append(SUFFIX);


        attributeContext.putAttribute(BODY_KEY,
Attribute.createTemplateAttribute(builder.toString()));

        super.renderMergedOutputModel(model, request, response);
    }


}


On Mon, Nov 16, 2009 at 2:03 AM, Antonio Petrelli <
[email protected]> wrote:

> 2009/11/15 Todd Nine <[email protected]>:
> >  I extend an existing spring class to dynamically
> > determine which page will be defined as the "body" definition.  This
> works
> > well.  However I want each of my body pages to define what the title will
> be
> > on the layout page.
>
> I think that you may solve both of your needs (custom body and custom
> title) by using a preparer and/or a placeholder:
>
>    <definition name="*/prefix*"
> template="/WEB-INF/views/layouts/default.jsp" preparer="my.Preparer">
>         <put-attribute name="title" value="Default Title"/>
>        <put-attribute name="header" value="/WEB-INF/views/tiles/header.jsp"
>  />
>        <put-attribute name="menu" value="/WEB-INF/views/tiles/menu.jsp" />
>        <put-attribute name="footer" value="/WEB-INF/views/tiles/footer.jsp"
>         <put-attribute name="body" value="/WEB-INF/edit/{2}.jsp" />
> />
>    </definition>
>
> You can even mix the placeholders with the preparer name.
> See:
> http://tiles.apache.org/framework/tutorial/advanced/preparer.html
> http://tiles.apache.org/framework/tutorial/advanced/wildcard.html
>
> HTH
> Antonio
>

Reply via email to