This is just an overview, so I have intentionally left out a lot of details, special cases, many additional features, etc. However, this should give you a good starting point.

First of all, your pageBeginRender implementation should normally immediately return if in the rewind phase (unless you want to do something special such as logging page events, etc.).
     if( event.getRequestCycle().isRewinding())
        return;

It would be very unusual to ever use getRequest().getParameter(). Tapestry page properties are set either by abstract or implemented bean methods (get / set / is). If this page is being invoked from another page, page properties can be set from the calling page. For example:

     TargetPage page = (TargetPage) cycle.getPage("TargetPage");
     page.setCrucualId(id);
     cycle.activate(page);

For Tapestry 3, abstract page properties must all be defined in your corresponding .page files as well.

If this page will be invoked directly from an outside application, or if you need the page to be bookmark-capable, or if the page for any other of various reasons needs to be invoked directly, then you can implement IExternalPage. Page parameters will be passed directly to the activateExternalPage method where you are free to set any page properties prior to render. The pageBeginRender method will be invoked after this as usual.

Typically, pageBeginRender is invoked to initialize the page from properties which (by this time) have already been set either by a calling page, by a previous render, or by external page initialization (by implementing IExternalPage). After page rendering is complete, the rendered response is sent to the client. The rewind phase is only invoked if a form is submitted. In this case, the form's listener method is invoked (where you can do whatever you like with the submitted form values), after which pageBeginRender will again be invoked to render the page.

Tapestry makes all of what you are trying to do very simple, but it is important to understand exactly how it works. Tapestry in Action covers all of this for Tapestry 3, and Kent Tong's book is a tremendous resource for Tapestry 4.

Shawn

Inge Solvoll wrote:
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



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

Reply via email to