我正在使用 jquery waypoints 和 jsf 实现无限滚动link http://kahimyang.info/kauswagan/code-blogs/1405/building-a-page-with-infinite-scroll-in-primefaces-using-waypoints-jquery-plugin。
我已经预渲染了需要无限滚动的 xhtml 之一。
现在,当 waypoint 发送 ajax 请求时,为什么每次滚动都会调用预渲染,这意味着整个页面正在刷新。
请让我知道如何解决这个问题。
你似乎认为preRenderView
事件在视图构造期间仅调用一次,并且不会在同一视图上的后续请求中调用。这是不真实的。这preRenderView
事件在渲染视图之前调用。视图呈现在每个请求。这还包括 ajax 请求(否则它如何为 ajax 请求生成必要的 HTML 输出?)。因此,您所看到的行为完全是预料之中的。您只是使用了错误的工具来完成这项工作。
您应该使用@PostConstruct
的方法@ViewScoped
bean,
@ManagedBean
@ViewScoped
public class Bean {
@PostConstruct
public void init() {
// Do here your thing during construction of the view.
}
// ...
}
或者添加否定检查FacesContext#isPostback()
在预渲染视图事件监听器中
public void preRender() {
if (!FacesContext.getCurrentInstance().isPostback()) {
// Do here your thing which should run on initial (GET) request only.
}
}
也可以看看:
- 何时使用 f:viewAction / preRenderView 与 PostConstruct? https://stackoverflow.com/questions/9844526/when-to-use-prerenderview-versus-postconstruct/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)