有时,当使用<h:commandLink>, <h:commandButton>或<f:ajax>时,与标记相关的action, actionListener或listener方法根本没有被调用。或者,bean属性没有更新提交的UIInput值。

可能的原因和解决方法是什么?


当前回答

我自己也遇到了这个问题,并发现了这个问题的另一个原因。 如果在支持bean中没有用于*.xhtml中使用的属性的setter方法,则不会调用该操作。

其他回答

还有一种可能性:如果症状是第一次调用有效,但随后的调用无效,那么您可能使用的是PrimeFaces 3。在JSF 2.2中,没有ViewState被发送。

如果你的h:commandLink在h:dataTable中,还有另一个原因,为什么h:commandLink可能不起作用:

绑定到h:dataTable的底层数据源也必须在单击链接时触发的第二个JSF-Lifecycle中可用。

因此,如果底层数据源是请求作用域,h:commandLink将不起作用!

这就是解决方法,对我来说很管用。

<p:commandButton id="b1" value="Save" process="userGroupSetupForm"
                    actionListener="#{userGroupSetupController.saveData()}" 
                    update="growl userGroupList userGroupSetupForm" />

这里,process="userGroupSetupForm"属性是Ajax调用的强制属性。actionListener从@ViewScope Bean调用一个方法。也更新咆哮消息,数据表:userGroupList和表单:userGroupSetupForm。

我修复了我的问题,放置:

<h:commandButton class="btn btn-danger" value = "Remove" action="#{deleteEmployeeBean.delete}"></h:commandButton>

In:

<h:form>
     <h:commandButton class="btn btn-danger" value = "Remove" action="#{deleteEmployeeBean.delete}"></h:commandButton>
</h:form>

我自己也遇到了这个问题,并发现了这个问题的另一个原因。 如果在支持bean中没有用于*.xhtml中使用的属性的setter方法,则不会调用该操作。