[英]JSF page element cannot trigger method from backing bean with action attribute.(JSF2.0 + primefaces)
[英]Primefaces / JSF button's action handler will not trigger the related bean's method
我是使用Primefaces框架的新手。
我的問題是,如果用戶單擊按鈕我想調用bean方法,但不會觸發該方法。 盡管如此,IntelliJ自動填充方法,我使用bean作為另一個控件的項目源,這是有效的。
Index.htmlx的部分內容
<h:form id="newLunch">
<h:panelGrid columns="2" style="width: 300px;">
<h:outputLabel for="initiator" value="Initiator" />
<p:inputText id="initiator" />
...
<p:button value="save" actionListener="#{indexBean.onSaveLunch}" />
</h:panelGrid>
</h:form>
IndexBean.java
@ManagedBean
@SessionScoped
public class IndexBean
{
public IndexBean()
{
//...
}
public void onSaveLunch()
{
// do some action, will not be triggered
}
}
謝謝你支持新手!
<p:button value="save" actionListener="#{indexBean.onSaveLunch}" />
在這里使用Primefaces CommandButton。
<p:commandButton value="save" actionListener="#{indexBean.onSaveLunch}" />
更多信息在這里
更新:
您的方法未被調用的原因,因為它對actionListener無效。
改變你的方法
public void onSaveLunch()
{
// do some action, will not be triggered
}
至
public void onSaveLunch(ActionEvent event)
{
// do some action, will not be triggered
}
記得import import javax.faces.event.ActionEvent;
因為還有另一個你不想使用的java swing動作事件。
您應該使用正確的組件和正確的屬性。 通過<p:commandButton>
更改<p:button>
並使用action
而不是actionListener
:
<p:commandButton value="save" action="#{indexBean.onSaveLunch}" />
如果這不起作用,那么代碼中的另一個問題是您沒有顯示。 為此,請使用當前代碼更新問題或從此處檢查原因: commandButton / commandLink / ajax action / listener方法未調用或輸入值未更新
更多信息:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.