Primefaces p:commandButton,未调用操作 [英] Primefaces p:commandButton with action not called
本文介绍了Primefaces p:commandButton,未调用操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Primefaces 3.2和JSF 2.1遇到了一些麻烦.
I've got some some troubles with Primefaces 3.2 and 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需要
When I take a look at Primefaces Showcase my p:commandButton need
actionListener="#{myBean.myActionMethod}"
我的Bean需要像这样的方法
and my Bean need a Method like
public void myActionMethod(){}
我的p:toolbar
标签周围有一个h:form
!
我的Bean是ViewScoped.
My Bean is ViewScoped.
我的解决方法是
在*.xhtml
文件
My Workaround is
In *.xhtml
File
<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
In MyBean.java
private String myEvent;
public void setMyEvent(String value){ myActionMethod();}
这对我有用,但是我认为这是非常肮脏的代码.
This works for me but I think this is very dirty code.
每个人都可以帮我吗?
推荐答案
尝试一下
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
page.xhtml
<p:toolbar>
<p:toolbarGroup>
<p:commandButton action="#{bean.testButtonAction}"/>
<p:commandButton actionListener="#{bean.testButtonActionListener}"/>
</p:toolbarGroup>
</p:toolbar>
这篇关于Primefaces p:commandButton,未调用操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文