preRenderView被称为每个ajax请求 [英] preRenderView is called on every ajax request

查看:298
本文介绍了preRenderView被称为每个ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我采取无限滚动使用jQuery的航点和JSF以下<一href="http://kahimyang.info/kauswagan/$c$c-blogs/1405/building-a-page-with-infinite-scroll-in-primefaces-using-waypoints-jquery-plugin"相对=nofollow>链接。 我有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.
    }
}

参见:

  • <一个href="http://stackoverflow.com/questions/9844526/when-to-use-$p$prenderview-versus-postconstruct/">When使用preRenderView与PostConstruct?
  • See also:

    • When to use preRenderView versus PostConstruct?
    • 这篇关于preRenderView被称为每个ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆