我在使用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();}
这对我有效,但我认为这是非常糟糕的代码。
大家能帮帮我吗?
type="button"
? - Matt Handy