【问题标题】:PF CommandButton(CB) action/actionListener is not called on click the second and not the third CB in a dataTable [duplicate]单击数据表中的第二个而不是第三个 CB 时不会调用 PF CommandButton(CB)动作/actionListener [重复]
【发布时间】:2016-08-16 09:58:10
【问题描述】:

我在最少两个屏幕/视图上面临这个问题,其中有许多在新窗口中打开对话框的命令按钮。我正在使用 Primefaces 5.3.5 和 JSF Mojarra 2.2.8。这些动作/动作监听器在弹出窗口中打开一个新对话框。第一个命令按钮总是打开新对话框,但其他命令按钮什么都不做。

<h:form id="dbuserForm">
          <!-- New User Button. This one fires a dialog -->
          <p:commandButton id="newUserGroupBtn" value="#{msg.WEB_BUTTONS_NEW}" style="margin-right: 2px;" actionListener="#{appUserData.toggleNewModal}" icon="fa fa-plus" accesskey="n" update="@form">
              <p:ajax event="dialogReturn" update="@form" />
          </p:commandButton>
    <p:dataTable id="tableDbUser" scrollable="true" width="100%" value="#{tabDbUser.listArray}" var="item" selectionMode="single" rowKey="#{item.idbuserId}">
          <!-- Delete User Button -->
          <p:column>
              <p:commandButton id="deleteAppUserBtn" value="#{msg.WEB_BUTTONS_DELETE}" style="margin-right: 2px;" actionListener="#{appUserData.toggleDeleteModal}" icon="fa fa-remove" accesskey="o" update="@form" disabled="#{appUserData.selectedUserName eq null or appUserData.selectedUserName eq ''}">
                    <p:ajax event="dialogReturn" update="@form" />
                </p:commandButton>
          </p:column>
          <!-- Modify User Button -->
          <p:column>
              <p:commandButton id="modifyAppUserBtn" value="#{msg.WEB_BUTTONS_OPEN}" style="margin-right: 2px;" actionListener="#{appUserData.toggleChangeModal}" icon="fa fa-edit" accesskey="o" update="@form" disabled="#{appUserData.selectedUserName eq null or appUserData.selectedUserName eq ''}">
                    <p:ajax event="dialogReturn" update="@form" />
          </p:column>
    </p:dataTable>
        </h:form>

和我的后端 bean

@Override
    public void toggleNewModal(ActionEvent event) {
        RequestContext.getCurrentInstance().openDialog("/dialogs/new-dbuser");
    }
@Override
    public void toggleDeleteModal(ActionEvent event) {
        RequestContext.getCurrentInstance().openDialog("/dialogs/del-report-dialog");
}

public void togglePasswordModal() {
        RequestContext.getCurrentInstance().openDialog("/dialogs/modify-dbuser");
    }

注意 新用户按钮只会触发此对话框(new-dbuser)。其他按钮什么也没触发,但它们是可点击的,我看不到任何错误。

我不知道这是否重要,但我的 bean 被配置为请求范围。

我知道这是 SO 中非常讨论的话题,但我还没有找到任何适合我的解决方案。感谢您的任何帮助。我真的被困住了,因为我没有看到任何错误。请有建设性。

【问题讨论】:

  • “我知道这是 SO 中非常讨论的话题,但我没有找到任何适合我的解决方案。” 请参阅 How to Ask。发布您发现的内容以及为什么它不起作用。并发布minimal reproducible example
  • @Kukeltje 谢谢,就是这样。请立即查看并注意新用户按钮只会触发一个对话框。
  • 关于这个问题还有哪些其他主题?他们没有为您解决什么问题。这就是我的意思。并尝试更改顺序?然后会发生什么?
  • “我不知道这是否重要,但我的 bean 被配置为请求范围。” 尝试更改范围?
  • @Kukeltje 谢谢,就是这样。我将它们改回会话范围,它们现在触发了。

标签: ajax jsf-2 primefaces


【解决方案1】:

在对话框 appendTo="(@body)" 中使用属性。使用 JS 打开和关闭对话框,如 PF('DialogVar').hide() 和 PF('DialogVar').show()。在任何操作更新对话框上。它会起作用的。 如果它没有发布您的对话框代码。 还要检查浏览器控制台。在那里你可能会发现一些错误。

【讨论】:

  • 我不在客户端使用对话框。我在我的后端 bean 中打开对话框。请看我的问题。
  • 这个问题和对话框框架有关,不是普通对话框。你不能像这样打开它们,并且 appendTo 根本不相关
猜你喜欢
  • 2014-12-20
  • 2012-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多