Inge Solvoll schreef:
I would like to provoke some debate on whether this is a good design pattern
or not:
public void pageBeginRender(PageEvent event) {
initState();
readItemsFromDatabase();
}
private Collection readItemsFromDatabase() {
return getDatabaseConnection().getItems();
}
private void initState() {
// Init all crucial page state here
}
Hi Inge,
I do that as well sometimes. Not sure if it is a good design pattern
though ;oP
There are times when you need some of the hidden parameters-values for
handling the pageBeginRender or PageValidate on the rewind-phase, while
the Hidden components haven't populated their properties yet. I don't
know of any other way of doing it but reading the values directly from
the request.
I generally run into a lot of problems trying to find a good pattern for
setting up data to fit with the RequestCycle. I have ended up doing the
database reading in the pageBeginRender method, meaning that my data for the
page is being read on every single rewind and render. I find it a bit hard
to understand how to achieve this:
If I have to fetch items from the database and I don't want to let
Tapestry persist them and I need them on both the rewind-phase as well
as the render-phase, then I usually make the properties for those items
concrete instead of abstract.
I also usually give those properties a lazy getter (if property is null,
fetch from database).
By making those properties concrete I have control over when they get
cleared. I only clear the properties after the render-phase (not after
the rewind-phase). Since the same page-instance gets used for rendering
after a rewind has taken place (same request is being handled), I only
need to fetch the data from the database once.
If anyone has any better solution to this, I would love to hear about it.
Regards,
Onno
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]