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

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


当前回答

我最近遇到了一个问题,在使用IBM Extended Faces Components的JSF 1.2应用程序中没有调用uiccommand。

我在数据表的一行上有一个命令按钮(扩展版本,所以<hx:datatable>), UICommand不会从表中的某些行中触发(不会触发的行是大于默认行显示大小的行)。

我有一个下拉组件,用于选择要显示的行数。支持该字段的值在RequestScope中。支持表本身的数据在某种ViewScope中(实际上,暂时在SessionScope中)。

如果通过绑定到数据表的rows属性的控件来增加行显示,那么在单击此更改后显示的任何行都不能触发UICommand。

将此属性置于与表数据本身相同的作用域中可以解决这个问题。

我认为这在上面的balusc# 4中有所暗示,但不仅表值需要为View或Session范围,而且还需要控制表上显示的行数的属性。

其他回答

我最近遇到了一个问题,在使用IBM Extended Faces Components的JSF 1.2应用程序中没有调用uiccommand。

我在数据表的一行上有一个命令按钮(扩展版本,所以<hx:datatable>), UICommand不会从表中的某些行中触发(不会触发的行是大于默认行显示大小的行)。

我有一个下拉组件,用于选择要显示的行数。支持该字段的值在RequestScope中。支持表本身的数据在某种ViewScope中(实际上,暂时在SessionScope中)。

如果通过绑定到数据表的rows属性的控件来增加行显示,那么在单击此更改后显示的任何行都不能触发UICommand。

将此属性置于与表数据本身相同的作用域中可以解决这个问题。

我认为这在上面的balusc# 4中有所暗示,但不仅表值需要为View或Session范围,而且还需要控制表上显示的行数的属性。

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

<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方法,则不会调用该操作。

<ui:composition>  
  <h:form id="form1">
    <p:dialog id="dialog1">
      <p:commandButton value="Save" action="#{bean.method1}" /> <!--Working-->
    </p:dialog>
  </h:form>

  <h:form id="form2">
    <p:dialog id="dialog2">
      <p:commandButton value="Save" action="#{bean.method2}" /> <!--Not Working-->
    </p:dialog>
  </h:form>
</ui:composition>

来解决;

<ui:composition>  
  <h:form id="form1">
    <p:dialog id="dialog1">
      <p:commandButton value="Save" action="#{bean.method1}" />   <!-- Working  -->
    </p:dialog>

    <p:dialog id="dialog2">
      <p:commandButton value="Save" action="#{bean.method2}" />   <!--Working  -->
    </p:dialog>
  </h:form>
  <h:form id="form2">
    <!-- ..........  -->
  </h:form>
</ui:composition>