Whoops... you're right. Sorry about that. I didn't try it with
anything else in the page. I just grabbed the last element before
rendering the template, then found it after rendering and grabbed the
next element after that....

@SupportsInformalParameters
public class Inf {

    @Inject
    private ComponentResources _resources;

    private Element _lastChild;

    void beforeRenderTemplate(MarkupWriter writer) {
        final Element parent = writer.getElement();
        _lastChild = null;
        // mark the last child
        for (Node child : parent.getChildren()) {
            if (child instanceof Element) {
                _lastChild = (Element) child;
            }
        }
    }

    void afterRenderTemplate(MarkupWriter writer) {
        Element wrapper = null;

        final Element parent = writer.getElement();
        boolean afterLast = false;
        for (Node child : parent.getChildren()) {
            if (!(child instanceof Element)) continue;

            if (_lastChild == null || afterLast) {
                wrapper = (Element) child;
                break;
            }

            if (child.equals(_lastChild)) afterLast = true;
        }

        if (wrapper != null) {
            final List<String> names = _resources.getInformalParameterNames();
            for (String name : names) {
                wrapper.attribute(name,
_resources.getInformalParameter(name, String.class));
            }
        }

    }
}


On Mon, Sep 21, 2009 at 2:57 AM, Kai Weber <kai.we...@glorybox.de> wrote:
> Josh Canfield schrieb:
>
>> This component will grab the first element from the template and add
>> all the informal parameters to it.
>
> Cool.
>
> But it grabs the first element of the outer component. If I have
>
> + form +
>       |
>       +- div
>       |
>       +- div
>       |
>       +- component
>
> it always grabs the form-Element and then the first div. I tried and tried 
> but in every render phase writer.getElement() returns only the form-Element. 
> I want to get the "component"-Element which I get with
>
> Regards, Kai
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>



-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to