You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Kai Weber <ka...@glorybox.de> on 2009/09/18 18:12:05 UTC

RenderInformals on Component With Template

Hi,

I have *exactly* the same problem as the user adamh in June 2008. He hasn't got an answer. Does, one year later, anyone has a glue?

http://www.nabble.com/RenderInformals-on-Component-With-Template-tt18053261.html#a18053261

In short this is his problem:

Inf.tml
<div existing="existing" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
        Inf Component
</div>

InfTest.tml
<div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">

<!-- This inf component should render with 'existing' and 'inf1' attributes -->
<t:inf inf1="inf1">Hi</t:inf>

</div>

Regards, Kai

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


Re: RenderInformals on Component With Template

Posted by Josh Canfield <jo...@thedailytube.com>.
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 <ka...@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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: RenderInformals on Component With Template

Posted by Kai Weber <ka...@glorybox.de>.
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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: RenderInformals on Component With Template

Posted by Josh Canfield <jo...@thedailytube.com>.
This component will grab the first element from the template and add
all the informal parameters to it.

@SupportsInformalParameters
public class Inf {

    @Inject
    private ComponentResources _resources;

    void afterRenderTemplate(MarkupWriter writer) {
        Element wrapper = null;
        // find first element added by the template (could be comment etc...)
        for (Node child : writer.getElement().getChildren()) {
            if (child instanceof Element) {
                wrapper = (Element) child;
                break;
            }
        }

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

Josh


On Fri, Sep 18, 2009 at 9:12 AM, Kai Weber <ka...@glorybox.de> wrote:
> Hi,
>
> I have *exactly* the same problem as the user adamh in June 2008. He hasn't got an answer. Does, one year later, anyone has a glue?
>
> http://www.nabble.com/RenderInformals-on-Component-With-Template-tt18053261.html#a18053261
>
> In short this is his problem:
>
> Inf.tml
> <div existing="existing" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
>        Inf Component
> </div>
>
> InfTest.tml
> <div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
>
> <!-- This inf component should render with 'existing' and 'inf1' attributes -->
> <t:inf inf1="inf1">Hi</t:inf>
>
> </div>
>
> Regards, Kai
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org