preRenderView被称为每个ajax请求被称为、preRenderView、ajax

2023-09-11 00:51:48 作者:朕就是辣么酷

我采取无限滚动使用jQuery的航点和JSF以下链接。 我有prerender为在其无限滚动所需的XHTML之一。 现在,作为航点发送Ajax请求,为什么每一个滚动它调用prerender这意味着整个页面是越来越refeshed。 请让我知道如何解决这个问题。

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.

推荐答案

您似乎认为 preRenderView 事件的施工过程中被调用一次查看并上了同样的看法后续请求不被调用。这是不真实的。该 preRenderView 事件被渲染视图前右侧调用。该视图显示在每次请求。这也包括Ajax请求(应该怎么回事产生了Ajax请求所需的HTML输出?)。所以,你所看到的行为完全可以预料。你用简单的错误的工具的工作。

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.

您应该要么使用 @ViewScoped bean的 @PostConstruct 方法

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.
    }

    // ...
}

或将增加对的FacesContext#的IsPostBack否定检查()在pre渲染视图事件侦听器

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.
    }
}

参见:

When使用preRenderView与PostConstruct?

See also:

When to use preRenderView versus PostConstruct?