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
}
My problem is that some ids in hidden inputs are needed by the initState
method. These values are not available in the pageBeginRender method during
rewind, because the Hidden components containing them haven't been rendered
yet. I need this state information on a per-request basis, not per-session,
so it is not possible to persist the page property. So far, I'm solving this
by using good-old request parameters, and reading them the old servlet way
in the pageBeginRender method like this:
String crucialId = getRequest().getParameter("crucialId");
page.setCrucialId(new Long(crucialId));
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:
On render:
- Read data from database and set page properties
On rewind:
- Create non-null, empty, page properties ready to be populated from the
request.
My rewind step here often fails, and I don't see why. My page properties
don't seem to be populated, when I leave them as, say, a non-null empty
java.util.Collection to be populated with items from the request.
Long and not very concentrated post, I actually don't know where to start
here :)
Inge