tags:

views:

697

answers:

2

So we have an f:event:

   <f:metadata>
    <f:event type="preRenderView" listener="#{dashboardBacking.loadProjectListFromDB}"/>
   </f:metadata>

Which is triggered as desired on initial page load (render).

However this preRenderView event is also triggered by an ajax partial page render, which re-renders an h:panelgroup with the id projectListing, as below.

<h:commandButton action="#{mrBean.addProject}" value="Create Project"
                                     title="Start a new project">
   <f:ajax render="projectListing" />
</h:commandButton>

I only want the dashboardBacking.loadProjectListFromDB to be called for the initial page render, but not when there is an ajax partial render. Is there a more appropriate event or method I could be using?

+1  A: 

You could try attaching the preRenderView event listener to an individual component, rather than the page. Choose a component that is not rendered during an Ajax request.

Brian Leathem
+1  A: 

Another option would be to put your preRenderView functionality in a @PostConstruct method of a "ViewScoped" managed bean. This logic would be executed when the bean is initialized, and you you maintain the same instance of the bean for all your ajax requests until you change views.

Brian Leathem
Thanks Brian, these are both good suggestions. I'll investigate both avenues today.
Andrew