4

I am implementing infinite scrolling using jquery waypoints and jsf following link . I have prerender for one of the xhtml on which infinite scrolling is required . Now, as waypoint sends ajax request so why for every scroll it is calling prerender that means whole page is getting refeshed. Please let me know how to solve this.

Rahul Singh
  • 781
  • 11
  • 27

1 Answers1

13

You seem to think that the preRenderView event is invoked only once during the construction of the view and not invoked on subsequent requests on the same view. This is untrue. The preRenderView event is invoked right before rendering of the view. The view is rendered on every request. This also includes ajax requests (how else should it produce the necessary HTML output for ajax requests?). So the behavior which you're seeing is fully expected. You was simply using the wrong tool for the job.

You should either be using the @PostConstruct method of a @ViewScoped bean,

@ManagedBean
@ViewScoped
public class Bean {

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

    // ...
}

or be adding a negation check on FacesContext#isPostback() in the pre render view event listener

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

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks @BalusC ,I have one more query.Actually i am not able to prevent "viewExpiredException".What i am doing is as below:- 1.)I have logged into application. 2.) Now i restarted the server 3.) now when i refresh the opened page it is directly going to error page but what should happen is it should navigate to login page as i have declared it in web.xml and on the prerender of login.xhtml i am checking for cookies if it is present then go directly to the homepage. Please let me know what i am missing? – Rahul Singh Nov 14 '13 at 12:17
  • You're welcome. If you have a new and completely unrelated question, just press "Ask Question" button on right top. The comments of an answer on a different question is not the right place for that. It's not possible to post and accept an answer on that and nobody in the future would be able to find the answer by search whenever they have the same question. – BalusC Nov 14 '13 at 12:18
  • Ok @BalusC,i have posted question and link for it is [link](http://stackoverflow.com/questions/19977548/how-to-avoid-viewexpired-exception-in-jsf) – Rahul Singh Nov 14 '13 at 12:25