在 JSF 2 中,绑定过程发生在执行操作之前

发布于 2024-12-22 13:37:41 字数 1504 浏览 0 评论 0原文

我将 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:pannelGroups, 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十年九夏 2024-12-29 13:37:41

因为这是自然的方式,正如您在 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文