在 JSF 2 中,绑定过程发生在执行操作之前
我将 PrimeFaces 与 JSF 2.0 一起使用,我有这样的布局:
<h:panelGroup layout="block" id="panelGroup" binding="#{bean.boundPg}" />
<p:commandButton value="Update" action="#{bean.updateMe}" update="panelGroup" />
其中,bean 是 SessionBean
。通过使用 log4j 进行调试,我发现绑定过程在执行 updateMe
操作之前调用了 getBoundPg
。所以视图总是过时的。
你知道为什么以及如何颠倒这个顺序吗?谢谢!
------------- 编辑 ---------------
我正在为问答游戏制作一个网络应用程序。
<h:panelGroup layout="block" id="pgContents" binding="#{bean.boundContents}" />
<p:commandButton value="Prev page" action="#{bean.prevPage}" update="pgContents" />
<p:commandButton value="Next page" action="#{bean.nextPage}" update="pgContents" />
pgContents
包含许多 h:pannelGroup
,每个子组包含一个显示测验内容的标签,一个用于播放器的 h:inputText
给出他们的答案。由于某些原因,我必须以编程方式生成 pgContents 的子级。
上一页
和下一页
按钮将检索上一组/下一组测验
下面是bean(跳过getters和setters)
@ManagedBean(name = "bean")
@SessionScoped
public class LessonHelper {
private int currentPage;
private HtmlPanelGroup boundContents;
public void prevPage() {
// decrease currentPage
// fetch contents
// add children for boundContents (label, inputText)
}
// nextPage() is similar
}
我的问题是,当我单击Prev/Next 按钮,绑定过程中先调用 getter getBoundContents
,后调用 prevPage()/nextPage()
,导致内容始终显示已经过时了。
I'm using PrimeFaces with JSF 2.0, I have this layout:
<h:panelGroup layout="block" id="panelGroup" binding="#{bean.boundPg}" />
<p:commandButton value="Update" action="#{bean.updateMe}" update="panelGroup" />
in which, the bean is SessionBean
. By using log4j to debug I found out that the binding process called getBoundPg
before executing the action updateMe
. So the view is always out-of-date.
Do you know why and how to reverse that order? Thanks!
------------- Edit ---------------
I'm making a web app for a quiz game.
<h:panelGroup layout="block" id="pgContents" binding="#{bean.boundContents}" />
<p:commandButton value="Prev page" action="#{bean.prevPage}" update="pgContents" />
<p:commandButton value="Next page" action="#{bean.nextPage}" update="pgContents" />
pgContents
contains many h:pannelGroup
s, each sub-group contains a label showing the content of a quiz, a h:inputText
for the player to give their answer. Because of some reasons, I had to generate the children of pgContents
programmatically.
The Prev page
and Next page
buttons will retrieve the prev/next group of quiz
Below is the bean (getters & setters are skipped)
@ManagedBean(name = "bean")
@SessionScoped
public class LessonHelper {
private int currentPage;
private HtmlPanelGroup boundContents;
public void prevPage() {
// decrease currentPage
// fetch contents
// add children for boundContents (label, inputText)
}
// nextPage() is similar
}
My problem is that, when I click the Prev/Next button, the getter getBoundContents
is called first in binding process, and the prevPage()/nextPage()
is called later, which cause the content always out-of-date.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为这是自然的方式,正如您在 BalusC 的精彩教程中看到的那样: http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html
准确地告诉我你想做什么,显示该 bean 中的内容和解决方案到你的问题就会被发现!
Because this is the natural way, as you can see in this wonderful tutorial by BalusC: http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html
Tell me exactly what do you want to do, show what's inside that bean and a solution to your problem will be found!