>> Pretty much like this
>> <t:loop source="boxes" value="var:whatever">
>>        <t:box source="var:whatever">
>> </t:loop>
>>
>> but this is obviously wrong. Is there a way to do so ?
>
> This looks obviously right to me. :) What could be wrong about placing a
> component inside a loop or a grid? For each iteration, a new instance be be
> created.

Component instances are created when your page is initially parsed,
not during rendering. So in this case you get one instance of the
component, not an instance for each iteration. This is important
because if you have local variables in your component they are not
reset by tapestry for each iteration of the loop. You can test this
with a simple Counter component.

public class Counter {

    @Property
    private int _count;

    int defaultCount() {
        return 0;
    }

    void setupRender() {
        _count++;
    }

    void beginRender(MarkupWriter writer) {
        writer.element("div");
        writer.write(Integer.toString(_count));
        writer.end();
    }
}

Josh


On Thu, Dec 3, 2009 at 3:28 AM, Thiago H. de Paula Figueiredo
<thiag...@gmail.com> wrote:
> Em Thu, 03 Dec 2009 07:21:16 -0200, Steven Tönsing
> <steven.toens...@artundweise.de> escreveu:
>
>> Hi,
>
> Hi!
>
>> So this is my sitiation :
>> I'm using tapestry 5.1 and i have a collection of components (Boxes) which
>> can be placed on a page (in a certain order) the only thing i whant to do
>> now is to get this collection of components rendered in the markup
>> (template) of the page.
>
>>                boxes.add( new Box("box 1") );
>
> Don't forget that you *cannot* instantiate pages or components directly.
>
>> Pretty much like this
>> <t:loop source="boxes" value="var:whatever">
>>        <t:box source="var:whatever">
>> </t:loop>
>>
>> but this is obviously wrong. Is there a way to do so ?
>
> This looks obviously right to me. :) What could be wrong about placing a
> component inside a loop or a grid? For each iteration, a new instance be be
> created.
>
>> public class Box {
>>       �...@parameter
>>       �...@property
>>        private String name = "noname";
>
> This isn't the right way of giving a default value to a parameter. Anyway,
> it is almost always a bad idea to initialize page or component fields in
> their declaration. You shoud use the value attribute of @Parameter to do
> that.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and
> instructor
> Owner, software architect and developer, Ars Machina Tecnologia da
> Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> 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