1 Reply Latest reply on Feb 27, 2010 5:37 AM by Nick Belaevski

    Request-scoped beans and datamodel initialization in PhaseListener

    Markos Fragkakis Newbie

      Ok, this is a tricky one, so heads up:


      I need to keep ABSOLUTELY minimal footpring in the session. So, no session-scoped beans, except the absolutely necessary. I must not even use a4j:keepAlive (because temporarily, we assume it keeps the beans in session until the user navigates away).

       

      SO: I have session beans to hold the information needed, such as  filtering, sorting and pagination. Each time a request is made, even in the same form, (ie the user toggles the Sorting in a column, or  sets a filter in a filtering field), the backing bean holding the  datamodel is re-created all over, and the datamodel is instantiated querying the DB.

       

      As a reminder, these are the phases of JSF:

      Restore View -->Apply Request Values --> Process Validations  --> Update Model --> Invoke Application --> Render Response

       

      Although sorting and filtering work OK, I have a problem is with datascroller pages. At first, although I keep the current page in a session bean, the sorting and filtering did not work as expected. This was related to the way I initialized the datamodel, which was lazily, when the getter was called on the backing bean  by the rich:datatable. This first took in the Apply Request Values Phase. However, the setter for the page of the datascroller was invoked in the Invoke  Application Phase, after the datamodel was initialized with the previous sorting and filtering stored in the session.

       

      The solution I found was drop the initialization in the getter, and instead initialize the datamodel with a Phase Listener before the Render Response Phase (the last phase), so that the datamodel would have the time to be initialized with the new filtering and sorting.

       

      That caused a problem with the datascroller, which stopped invoking the setter for the page (in the Invoke Application phase). I think that this may be related with the fact that the datamodel is null up until the Render Response phase.

       

      Any idea how I could overcome the problem? I.E. what phase should I initialize the datamodel manually? Any other proposal on how to debug / proceed?

       

      Cheers!