PreRenderView is called for every ajax request

I implement endless scrolling using jQuery waypoints and jsf following. I have a prerender for one of xhtml which requires infinite scrolling. Now that the waypoint sends an ajax request, why does it call a prerender for each scroll, which means the whole page is getting refreshed. Please let me know how to solve this.

+4
source share
1 answer

It seems that the event preRenderViewis fired only once during the construction of the view and is not fired on subsequent requests on the same view. This is not true. An event preRenderViewis fired just before the view is visualized. A view is displayed in each request . This also includes ajax requests (how else should it generate the necessary HTML output for ajax requests?). Thus, the behavior you see is fully expected. You just used the wrong tool to work.

You must either use the method @PostConstructfor @ViewScopedbean,

@ManagedBean
@ViewScoped
public class Bean {

    @PostConstruct
    public void init() {
        // Do here your thing during construction of the view.
    }

    // ...
}

or add a denial check on the FacesContext#isPostback()render preview event listener

public void preRender() {
    if (!FacesContext.getCurrentInstance().isPostback()) {
        // Do here your thing which should run on initial (GET) request only.
    }
}

See also:

+12

All Articles