You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Pawel Kozlowski <pk...@amadeus.com> on 2007/06/11 10:56:57 UTC

Adding new attribute type....

Hi All,

First of all, thnx for all the hard work put in the Tiles2 development. 
It's good to see old, good library with refreshed API.

Speaking about the API: I was trying to add a new attribute type to Tiles2 
and I've found that this is not a trivial task? I mean, I can find all the 
places to tweak, but I'm a little bit scared of changing 
BasicTilesContainer. For me, the problems comes from the:

 public void render(Attribute attr, Writer writer, Object... requestItems)

method. More specifically, this switch statement is kind of problematic:

switch (type) {
            case OBJECT:
                throw new TilesException(
                    "Cannot insert an attribute of 'object' type");
            case STRING:
                writer.write(attr.getValue().toString());
                break;
            case DEFINITION:
                render(request, attr.getValue().toString());
                break;
            case TEMPLATE:
                request.dispatch(attr.getValue().toString());
                break;
            default: // should not happen
                throw new TilesException(
                        "Unrecognized type for attribute value "
                        + attr.getValue());
        }

It looks like I would need to change the AttributeType enum, definitions 
reader and the BasicTilesContainer? 

I was wondering if it would be possible to change an implementation in the 
way that each attribute is responsible for rendering itself. I know this 
is quite a change, but I was wondering if such a design was ever 
considered. Sorry if I'm blind and can't see obvious problems with such a 
design?. I would be really grateful for any feedback. Basically, my goal 
is to add a new type of attribute and not to rewrite to much chunks of 
Tiles2.

Thnx,
Pawel

Re: Adding new attribute type....

Posted by Antonio Petrelli <an...@gmail.com>.
2007/6/11, Pawel Kozlowski <pk...@amadeus.com>:
> Speaking about the API: I was trying to add a new attribute type to Tiles2
> and I've found that this is not a trivial task?

In fact you cannot do it :-)

> I mean, I can find all the
> places to tweak, but I'm a little bit scared of changing
> BasicTilesContainer.

Why are you scared? I guess it doesn't bite :-) Jokes apart, what
exactly are going to accomplish? We can help you achieving your
objectives if you tell us what they are.

> I was wondering if it would be possible to change an implementation in the
> way that each attribute is responsible for rendering itself. I know this
> is quite a change, but I was wondering if such a design was ever
> considered.

I did not originally create the container, but I think that David (the
one that created it) thought about other frameworks. Correct me if I
am wrong, but, for example, in JSF the component does not render
itself, but a "renderer" renders it.

> Basically, my goal
> is to add a new type of attribute and not to rewrite to much chunks of
> Tiles2.

What is your attribute type and what does it represent?

Antonio