2012-10-12 25 views
14

Primeface 3.2とJSF 2.1にいくつかの問題があります。Primefaces p:アクションが呼び出されていないcommandButton

このようなマイコード:

<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> 

私は私のpを展示Primefacesを見てみましょう:commandButtonのは

actionListener="#{myBean.myActionMethod}" 

を必要とする、私のビーンが

public void myActionMethod(){} 

のような方法を必要とします私はp:toolbarタグの周りにh:formを持っています!

My BeanはViewScopedです。

私の回避策は、これが私の作品 MyBean.java

private String myEvent; 

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

でファイル

<p:commandButton type="button" title="#{msg.neu}" onclick="addNewEmptyFile()"/> 
<p:remoteCommand name="addNewEmptyFile" update=":codeTabForm"> 
    <f:setPropertyActionListener value="#{true}" target="#{myBean.myEvent}"/> 
</p:remoteCommand> 

*.xhtmlであるが、私は、これは非常に汚いコードだと思います。

誰も助けてくれますか?

+0

どこに問題がある?page.xhtml

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

この

Bean.javaをお試しくださいショーケースのようにしようとするとどうなりますか? –

+0

ActionListener Methodeを追加すると、イベントは呼び出されません。 – user1740789

+3

コマンドボタンから 'type =" button "'を削除しようとしましたか? –

答えて

11

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

IDEがメソッドのシグネチャの不一致を無視するのではなく、これについて開発者に警告する日が本当にありがとうございます; – Leo

+1

今後の参考のために:私の場合は、属性タイプ=ボタンをコピーして、私のボタンはなかった。 – Thomas

+2

削除タイプ= "ボタン"問題を修正しました – Fabii

関連する問題