tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Piterman <rpiter...@gmx.net>
Subject Re: [jira] Created: (TAPESTRY-733) Tapestry should call listeners (such as PageBeginRenderListener) in some predefined order
Date Tue, 01 Nov 2005 20:43:57 GMT
There are two things there:
The way the components pass the objects is fine - now you have to make 
sure, for example, that address is not null. Hope I got that right.

If you decide this logic belongs to the UI...
placing it in pageBeginRender is a bad idea - Its hard to explain why...
I use pageBeginRender to initialize rendering cycle, but not business or 
domain logic.

What I would do is make proxy methods:

on the page:

public Address getAddress() {
   Address a = getClient().getAddress();
   if (a == null) {
     a = new Address();
   return a;

This is the same code you would have used in pageBeginRender method of 
your component.

I Like it better because the component gets an Address. Its the 
responsibility of the container to make sure it gets one.

Otherwise, the component gets a client, and manipulates it, which 
interfears (logically, not necesserily practically) with the "work" of 
the container.

Hope its not topo fuzzy...

ציטוט Leonardo Quijano Vincenzi:
> Just how would you make it lazy??
> My scenario: a domain-driven approach to web development. I have several 
> domain classes, such as Client, Phone, Address, etc. For example, the 
> Client class would have something like this:
> Client.java
> -> String firstName
> -> String lastName
> -> List<Phone> phones
> -> Address address
> etc
> I then go and create a FormClient.html Tapestry component with something 
> like this:
> <span jwcid="@FieldLabel" displayName="First Name" /><span 
> jwcid="@TextField" value="ognl:value.firstName" />
> <span jwcid="@FieldLabel" displayName="Last Name" /><span 
> jwcid="@TextField" value="ognl:value.lastName" />
> <span jwcid="@For" source="ognl:value.phones" value="ognl:phone">
>   <span jwcid="@forms/FormPhone" value="ognl:phone" />
> </span>
> <span jwcid="@forms/FormAddress" value="ognl:value.address" />
> etc...
> As you see, I'm binding the subcomponents (FormPhone, FormAddress) with 
> the Client object directly. Then on rewind I have to do nothing: the 
> address is automatically assigned to value.address and so forth (the 
> list of phones is a special case, but similar).
> Now, the graph can get pretty complex, so I initialize every FormXXX 
> component's value (in case it's null) in pageBeginRender. But, for this 
> to work, the parent component must be already initialized, because, if I 
> try to do a setValue() on "value.address", it throws an NPE when and 
> value is null (since the parent hasn't been initialized yet).
> Summary: It's just a case of component composition. It's like using 
> constructors. The object's fields constructors are called after the 
> parent one.
> It's intuitive to assume events are fired in order [parent -> child]. At 
> least it took me a while to figure out what was going wrong.

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

View raw message