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.

--
Ing. Leonardo Quijano Vincenzi
Director Técnico
DTQ Software


Ron Piterman wrote:
I Usually avoid this kind of initialization by making it happen lazy,
If you would share the scenario... maybe there is a nice solution...
Cheers,
Ron




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to