gpt4 book ai didi

jsf - 素面 p :commandButton with action not called

转载 作者:行者123 更新时间:2023-12-03 20:49:14 26 4
gpt4 key购买 nike

我在 Primefaces 3.2 和 JSF 2.1 上遇到了一些麻烦。

我的代码是这样的:

<p:toolbar id="jeditortoolbar" styleClass="jeditortoolbar">
<p:toolbarGroup align="left" height="25" style="height:25px">
<p:commandButton type="button" title="#{msg.beenden}"/>
<p:commandButton type="button" title="#{msg.neu}"/>
</p:toolbarGroup>
</p:toolbar>

当我查看 Primefaces Showcase 我的 p:commandButton 需要
actionListener="#{myBean.myActionMethod}"

而我的 Bean 需要一个像
public void myActionMethod(){}

我有一个 h:form我的周围 p:toolbar标签!

我的 Bean 是 ViewScoped。

我的解决方法是
*.xhtml文件
<p:commandButton type="button" title="#{msg.neu}" onclick="addNewEmptyFile()"/>
<p:remoteCommand name="addNewEmptyFile" update=":codeTabForm">
<f:setPropertyActionListener value="#{true}" target="#{myBean.myEvent}"/>
</p:remoteCommand>

在 MyBean.java 中
private String myEvent;

public void setMyEvent(String value){ myActionMethod();}

这对我有用,但我认为这是非常脏的代码。

大家可以帮帮我吗?

最佳答案

尝试这个

Bean.java

@ManagedBean
@ViewScoped
public class Bean {

public String testButtonAction() {
System.out.println("testButtonAction invoked");
return "anotherPage.xhtml";
}

public void testButtonActionListener(ActionEvent event) {
System.out.println("testButtonActionListener invoked");
}

}

页面.xhtml
<p:toolbar>
<p:toolbarGroup>
<p:commandButton action="#{bean.testButtonAction}"/>
<p:commandButton actionListener="#{bean.testButtonActionListener}"/>
</p:toolbarGroup>
</p:toolbar>

关于jsf - 素面 p :commandButton with action not called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12856843/

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