簡體   English   中英

Primefaces p:commandButton,未調用動作

[英]Primefaces p:commandButton with action not called

我在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(){}

我的p:toolbar標簽周圍有一個h:form

我的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");
    }

}

page.xhtml

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM