【问题标题】:Commandlink action gets called before confirmdialog result在确认对话框结果之前调用 Commandlink 操作
【发布时间】:2014-04-07 12:19:49
【问题描述】:

我是 primefaces 的新手。我的问题是

我有一个 p:commandlink,我在其中调用了一个确认对话框。

但问题是,commandlink 中的 action 属性甚至在我们在确认对话框中单击(是/否)之前就被触发了。但期望是根据确认对话框触发动作。非常感谢任何帮助。

我的代码 sn-p:

<p:commandLink  value="Lock" disabled="#{bean.disableLock}" action="#{bean.lockdevice("hi" , 0)}" onclick="confirmation1.show();" type="button"  ajax="false" />
<p:confirmDialog message="Are you Sure ?"  header="Confirmation"  showEffect="fade" hideEffect="explode"  widgetVar="confirmation1"  appendTo="@(body)">
<p:commandButton value="Yes" type="button" onclick="confirmation1.hide()"/>
<p:commandButton value="No" type="button" onclick="confirmation1.hide()"/>
</p:confirmDialog>

提前致谢。

【问题讨论】:

    标签: jsf-2 primefaces


    【解决方案1】:

    您要么必须将操作放在“是”按钮上:

    <p:commandLink  value="Lock" disabled="#{bean.disableLock}" onclick="confirmation1.show();" type="button"  ajax="false" />
    <p:confirmDialog message="Are you Sure ?"  header="Confirmation"  showEffect="fade" hideEffect="explode"  widgetVar="confirmation1"  appendTo="@(body)">
      <p:commandButton value="Yes" type="button" onclick="confirmation1.hide()" action="#{bean.lockdevice("hi" , 0)}"/>
      <p:commandButton value="No" type="button" onclick="confirmation1.hide()"/>
    </p:confirmDialog>
    

    或使用p:confirm:

    <p:commandLink  value="Lock" disabled="#{bean.disableLock}" action="#{bean.lockdevice("hi" , 0)}" onclick="confirmation1.show();" type="button"  ajax="false">
      <p:confirm header="Confirmation" message="Are you sure?" icon="ui-icon-alert"/>
    </p:commandLink>
    

    看看showcase

    【讨论】:

    • 我照你说的做了(按照第二步)!但是现在,在确认对话框输入之后(比如我给出“是”)。该操作未触发。
    • 谢谢,实际上它正在工作!我删除了 onclick 属性,并将确认对话框全局属性设置为 true !现在它的工作。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多