gpt4 book ai didi

JSF 按钮操作触发了两次

转载 作者:行者123 更新时间:2023-12-04 20:02:36 27 4
gpt4 key购买 nike

我已经在 WildFly 论坛上问过这个问题,但到目前为止还没有得到任何答案。所以我在这里尝试。

自从我从 WildFly 8.1 升级到 8.2 后,连接到 bean 的 tabView 内的 commandButton 出现问题。

这是一个简单的 JSF 页面:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<h:form>
<p:tabView binding="#{testBean.tabView}">
<p:tab title="Tab">
<p:commandButton value="Inside" action="#{testBean.testInside}"/>
</p:tab>
</p:tabView>
<p:commandButton value="Outside" action="#{testBean.testOutside}"/>
</h:form>
</h:body>
</html>

和 bean :
@Named
@SessionScoped
public class TestBean implements Serializable {
private TabView tabView = new TabView();

public TabView getTabView() {
return tabView;
}

public void setTabView(TabView tabView) {
this.tabView = tabView;
}

public void testInside() {
System.out.println("inside");
}

public void testOutside() {
System.out.println("outside");
}
}

单击“内部”按钮触发 testInside() 两个 次。 “外部”按钮(在 tabView 之外)行为正常并且只触发一次它的方法。删除 tabView 绑定(bind)消除了这个问题。我正在使用 PrimeFaces 4.0。

感谢您的任何想法

最佳答案

这是一个 Mojarra 'issue' ,由 2.2.7 中的性能优化修复引入。

this is a Mojarra "issue", I've discovered it when working on RF-13920, it was introduced by JAVASERVERFACES-3193. The components that use binding are not recreated during a request to the server but their children are. With the original children still in place inserting the new children causes the "duplicate id" error.


所以看起来你的按钮被添加了两次,但由于你没有分配明确的 id,你不会得到重复的 id 错误......尝试一下可能会很有趣(添加明确的 id)

The JSF specification states that binding should only be used in Request scope, so I don't think it should be treated as a bug if this fails in Conversation scope.


最后一句话很有趣。正如在 jboss 网站上的下一篇文章中发布的那样:

But now I think I have a satisfying solution for this issue and I can confirm, that with request-scoped backing beans for the component binding the exception and duplicate id problem does not occur anymore, even with Mojarra 2.2.8 from Wildfly-8.2.0.Final!

This is even true if the rest of the logic for the page remains in a (say) conversation scoped bean. You just need to have a request-scoped bean for the binding attribute, which then can be referenced in EL and other beans.


另请查看 this post

关于JSF 按钮操作触发了两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28273156/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com