You may want to look at the method prepareForRender(). This is the
method that handles binding of properties to form values. It is also
called just before the component is rendered and in the order in which
they are rendered on the page (where pageBeginRender is called before
anything renders and is called in an undefined order). Also note that
prepareForRender is not called if the component is not rendered (for
instance if it is in an @Conditional that evaluates to false).

I have received the best results from using pageBeginRender for
initializing page properties that are static (ie known at all times
during render, for instance a property select model property) and
using prepareForRender in other times.

Ryan

On 2/14/06, Inge Solvoll <[EMAIL PROTECTED]> 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