【问题标题】:CommandButton not calling actionListener when I close confirmDialog当我关闭confirmDialog时CommandButton没有调用actionListener
【发布时间】:2015-03-09 17:08:44
【问题描述】:

我有调用保存方法的停止和释放按钮,并在保存方法中显示了一个确认对话框。我可以使用“停止”按钮,在对话框中按“确定”并且该方法有效,但是当我再次进入时钟释放时,该按钮不会调用 actionListener。类似点击释放,确认然后尝试停止。

这是两个命令按钮,位于 modeControls 内。

<p:commandButton title="Stop" value="Stop"
        rendered="#{unitSetVehicleStatusBean.crudMode == 'READ' and unitSetVehicleStatusBean.stopped =='false'}"
        actionListener="#{unitSetVehicleStatusBean.stop}"
        update="modeControls :mainForm" 
        process="@this :mainForm"/>
<p:commandButton title="Release" value="Release"
        rendered="#{unitSetVehicleStatusBean.crudMode == 'READ' and unitSetVehicleStatusBean.stopped =='true'}"
        actionListener="#{unitSetVehicleStatusBean.release}"            
        update="modeControls :mainForm" 
        process="@this :mainForm"/>

这里是确认对话框。它调用的 save 方法是从 stop() 和 release() 方法中调用的,然后经过一些验证后我使用

RequestContext context = RequestContext
                        .getCurrentInstance();
                context.execute("PF('saveNDTDialog').show();");
                break;

当用户在 ConfirmDialog 中选择 OK 时,它将通过 switch 语句重新加入此方法并完成保存。

这是确认对话框。

<p:confirmDialog id="saveNDTDialog" appendTo="@(body)"
            widgetVar="saveNDTDialog" closeOnEscape="true"
            closable="true"
            message="#{message.stoppedValidationNDTWarning}">
            <p:commandButton value="OK"
                update="mainForm :modeControls"
                actionListener="#{unitSetVehicleStatusBean.save('WARNING_NDT')}" 
                oncomplete="saveNDTDlg.hide();"/>
            <p:commandButton value="Cancel"
                onclick="saveNDTDlg.hide();" />
        </p:confirmDialog>

我认为问题与 appendTo 或可能与 onComplete 有关,但不太确定出了什么问题。

欢迎提出任何建议...

【问题讨论】:

  • 只是添加。如果我删除 confirmDialog 的调用并直接运行 save 方法,Stop 和 Release 按钮​​将完美运行。
  • 我相信 dialog.hide() 在 PF5(或者是 5.1)中已弃用。除非您使用旧的东西,否则我会像在 java 方法中那样做。另外我认为“saveNDTDlg”是错误的,除非你有几个对话框
  • 是的,我在 PF4 上。有几个对话框,我只是举了一个例子,以便于理解。我现在已经开始工作了,会在回答中解释..

标签: jsf primefaces dialog actionlistener


【解决方案1】:

通过将对话框拉出主窗体并在对话框中的 commandButtons 周围添加一个窗体,对话框开始按预期工作。

【讨论】:

  • PrimeFaces 论坛中有不止一篇关于此的帖子。我很好奇您是否在那里搜索以及您使用了哪些术语。只是想看看我是否可以尝试用一些评论“标记”那里的帖子,以便将来找到它们。顺便说一句,PrimeFaces 文档中也提到了这一点
  • 是的,我已经搜索并尝试过一次,但没有成功。我认为它不起作用,因为我将 oncomplete="saveHDTDlg.hide()" 更改为 omcomplete="PF('saveNDTDialog').hide();"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-12-26
  • 1970-01-01
  • 2014-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多