Праймы p: commandButton с действием, не вызываемым - программирование
Подтвердить что ты не робот

Праймы p: commandButton с действием, не вызываемым

У меня есть некоторые проблемы с 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();}

Это работает для меня, но я думаю, что это очень грязный код.

Могут ли все помочь мне?

4b9b3361

Ответ 1

Попробуйте это

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>