Marin� A. J�nsson said:
...
> I miss seeing a listing for Tiles and Modules in the Status doc though.  As
> I've already stated I have a� working TilesTool to contribute (although it
> lacks support for put-lists).  I could also use struts modules in my
> projects ... so maybe I can lend a hand with that?

yeah, i would love it if you'd lend a hand!  i haven't used either Tiles or
Modules, and really don't know a lot about them.  any help you could give
would be fantastic. patches and contributions are more than welcome.
sometimes it feels like a one man show these days.  i'm very eager to get more
developers involved (and hopefully some will merit becoming committers).

i've looked into Tiles a little.  Tom Czarniecki also posted a TilesTool that
he made to the user list.  but i'm not sure how to use it or evaluate it given
my current level of understanding.  i'd be interested to hear your thoughts on
it and see your code too (an example of how to use it might help me understand
:).  anyway, i've reposted his email at the bottom of this one in case you
missed it.

Nathan Bubna
[EMAIL PROTECTED]

-----------------------------------------------------------------
from: [EMAIL PROTECTED]
-----------------------------------------------------------------
Hi there,
I would like to contribute my version of a tiles tool for velocity. This
tool is designed to be used as part of a velocity toolbox and provides a
simple way of accessing struts-tiles defintions to allow velocity templates
to be used in the struts-tiles framework rather than jsp pages. This tool
does not parse nested component contexts since that is not required for my
purposes but it can easily be extended.

I use this tool with the following velocimacro:
## Parse a VM template returned by a Tiles definition.
#macro(tilesParse $name)
#if( $tiles.exists($name) )
#parse( $tiles.get($name) )
#end
#end

Source code follows:
/*
 * $Id: TilesTool.java,v 1.1 2003/07/13 03:51:24 Tom Exp $
 */
package com.tomczarniecki.velocity;

import org.apache.struts.taglib.tiles.ComponentConstants;
import org.apache.struts.tiles.ComponentContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.tools.view.context.ViewContext;
import org.apache.velocity.tools.view.tools.ViewTool;

/**
 * TODO: add description
 *
 * @author  Tom Czarniecki
 * @version $Revision: 1.1 $
 */
public class TilesTool implements ViewTool {

    //
------------------------------------------------------------------------
    // Class variables and constants

    //
------------------------------------------------------------------------
    // Instance variables

    private ViewContext m_viewCtx;

    //
------------------------------------------------------------------------
    // Constructor(s)

    //
------------------------------------------------------------------------
    // Public methods

    public void init(Object obj) {
        if (obj instanceof ViewContext) {
            m_viewCtx = (ViewContext) obj;
        } else {
            throw new IllegalArgumentException(
                    "Tool can only be initialized with a ViewContext");
        }
    }

    public String get(String name) {
        Object ctx =
m_viewCtx.getRequest().getAttribute(ComponentConstants.COMPONENT_CONTEXT);
        if (ctx instanceof ComponentContext) {
            ComponentContext compCtx = (ComponentContext) ctx;
            Object value = compCtx.getAttribute(name);
            if (value instanceof String) {
                return (String) value;
            } else {
                Velocity.warn("Invalid ComponentContext attribute class for
key '" + name +
                        "': expected " + String.class + ", actual " +
getClassName(value));
            }
        } else {
            Velocity.warn("Invalid HttpServletRequest attribute class for
key '" +
                    ComponentConstants.COMPONENT_CONTEXT + "': expected " +
                    ComponentContext.class + ", actual " + getClassName(ctx));
        }
        return "";
    }

    public boolean exists(String name) {
        String value = get(name);
        return (value.length() > 0);
    }

    //
------------------------------------------------------------------------
    // Private methods

    private String getClassName(Object obj) {
        return (obj != null) ? obj.getClass().getName() : "null";
    }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to