3 Replies Latest reply on Jan 6, 2010 2:19 PM by mwohlf

    Page params + action doubt.

    fmontezuma

      I have a page with a parameter in the URL and I want to load data based on it, but I have to convert/validate this parameter, so I used page params to do it.


      If I use a page action to load the data and use pagination the page action is called everytime I click to move to another page. Anyway to change this? I want to load data only once during the conversation scope.


      I tried to use @Create, but this method is called before the page params are inserted in the bean. The same doesn't happen when I use @RequestParameter.


      Thanks.

        • 1. Re: Page params + action doubt.
          fmontezuma

          I read in Seam in Action (page 125) that to ensure that a page action get executed only during an initial request I should use the conditional:


          <action execute="#{actionBean.executeOnInitialRequestOnly}" 
             if="#{empty param['javax.faces.ViewState']}"/>



          It have a footnote saying that in JSF 1.2, this check is performed by the ResponseStateManager isPostback(FacesContext) method.


          I didn't understand what he mean with this.


          • 2. Re: Page params + action doubt.
            germanescobar

            You need to define the actionBean.executeOnInitialRequestOnly() method somewhere like this:




            @Name("actionBean")
            public class ActionBean {
            
              public boolean executeOnInitialRequestOnly() {
                ResponseStateManager rtm = FacesContext.getCurrentInstance().
                    getRenderKit().getResponseStateManager();
                return rtm.isPostback(FacesContext.getCurrentInstance());
              }
                 
            }





            This way you ensure that your page action method will be called only once when the page is loaded for the first time and not on postback.


            Hope it helps!

            • 3. Re: Page params + action doubt.
              mwohlf

              not sure if I miss something here, but I wonder why you don't use on-postback="false" like so:




                <action execute="#{actionBean.executeSomeMethod}" on-postback="false" />