You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Inge Solvoll <in...@gmail.com> on 2009/02/12 12:05:56 UTC

T5: Components listening to page form events

Hi!

I have a component that needs to listen to events from a form that resides
in the containing page. The component takes care of viewing a list of
selectable items, and this list and its PrimaryKeyEncoder needs to be
initialized through the prepare event of the containing form.

In my mind, it seems perfectly logical that form events like PREPARE and
SUBMIT would trigger methods (onPrepare, onSubmit) in components inside the
form component on the page. But in my setup now, only the onPrepare and
onSubmit methods of the page is called.

Where am I getting this wrong? Aren't components supposed to get access to
form events from their containers?

Regards

Inge

Re: T5: Components listening to page form events

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, Feb 13, 2009 at 6:03 AM, Inge Solvoll <in...@gmail.com> wrote:
> In Jumpstart, the example tells me to put the initializing code for the loop
> source collection and its PrimaryKeyEncoder in the onPrepare event handler.
> Is this the recommended best practice? Are there other nice approaches to
> this?

I guess I use event handler methods to set up page class fields a lot
less than the average . . . I basically only use the prepare event
from the Form component.
For your problem, I would have a getPrimaryKeyEncoder() with lazy
initialization:

@Retain
private PrimaryKeyEncoder primaryKeyEncoder;

public PrimaryKeyEncoder getPrimaryKeyEncoder() {
    if (primaryKeyEncoder == null) {
        primaryKeyEncoder = .... // create or get our primary key encoder here
    }
    return primaryKeyEncoder;
}

Sometimes I feel Tapestry 5 is so easy that people often start trying
a complex solution before the easy one. :)

-- 
Thiago

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


Re: T5: Components listening to page form events

Posted by Inge Solvoll <in...@gmail.com>.
Ok, so I'm not using the right pattern here then. I'm curious about how I
should approach my problem:

I have a recurring form pattern in my application, where I need a list of
checkable items as part of a form. The code for viewing it and retrieving
the checked values on submit is common. If this is a component, I only need
to specify the list of objects to be used. But if it is a component, it
should handle its own PrimaryKeyEncoder, which needs to be initialized both
on setupRender and on form onPrepare. Without hooks to form events, this
can't be done.

I also should mention that I'm a bit shaky about loops in forms in Tapestry
5, I'm learning as we speak. Maybe I'm stupid, but form loops have been a
big stumbling point in both the adoption of T4 and T5 in our application.
This time around, I've spent a couple of days trying to make my listener
method get the correctly updated values from my loop in the tml. With T4, I
often ended up just session persisting the source of loops, because it was
the only way to ensure that it "just worked" on submit. This time, I won't
do that...

In Jumpstart, the example tells me to put the initializing code for the loop
source collection and its PrimaryKeyEncoder in the onPrepare event handler.
Is this the recommended best practice? Are there other nice approaches to
this?

Thanks for putting up with all of us stupid users, Tapestry people :)

Regards
Inge

On Fri, Feb 13, 2009 at 1:59 AM, Howard Lewis Ship <hl...@gmail.com> wrote:

> On Thu, Feb 12, 2009 at 3:05 AM, Inge Solvoll <in...@gmail.com>
> wrote:
> > Hi!
> >
> > I have a component that needs to listen to events from a form that
> resides
> > in the containing page. The component takes care of viewing a list of
> > selectable items, and this list and its PrimaryKeyEncoder needs to be
> > initialized through the prepare event of the containing form.
> >
> > In my mind, it seems perfectly logical that form events like PREPARE and
> > SUBMIT would trigger methods (onPrepare, onSubmit) in components inside
> the
> > form component on the page. But in my setup now, only the onPrepare and
> > onSubmit methods of the page is called.
> >
> > Where am I getting this wrong? Aren't components supposed to get access
> to
> > form events from their containers?
>
> Events propogate up, not down. So the events are triggered by the
> Form, and move up to its container (the page).
>
> >
> > Regards
> >
> > Inge
> >
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator Apache Tapestry and Apache HiveMind
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: Components listening to page form events

Posted by Howard Lewis Ship <hl...@gmail.com>.
On Thu, Feb 12, 2009 at 3:05 AM, Inge Solvoll <in...@gmail.com> wrote:
> Hi!
>
> I have a component that needs to listen to events from a form that resides
> in the containing page. The component takes care of viewing a list of
> selectable items, and this list and its PrimaryKeyEncoder needs to be
> initialized through the prepare event of the containing form.
>
> In my mind, it seems perfectly logical that form events like PREPARE and
> SUBMIT would trigger methods (onPrepare, onSubmit) in components inside the
> form component on the page. But in my setup now, only the onPrepare and
> onSubmit methods of the page is called.
>
> Where am I getting this wrong? Aren't components supposed to get access to
> form events from their containers?

Events propogate up, not down. So the events are triggered by the
Form, and move up to its container (the page).

>
> Regards
>
> Inge
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

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