【问题标题】:Can't display object details in deletion confirmation dialog无法在删除确认对话框中显示对象详细信息
【发布时间】:2014-09-05 11:40:39
【问题描述】:

这是我在数据表列中的命令按钮,它的任务是删除关联的行对象:

   <p:column style="width:6%;text-align:center"
   headerText="Delete">
    <p:commandButton icon="ui-icon-close"
     title="Delete release #{release.name}"
     actionListener="#{releaseBean.deleteRelease(release)}"
     process="@this" update=":display :form2:releaseList">
        <p:confirm
          header="Confirm deleting release #{release.name}"
          message="Are you really sure you want to delete release #{release.name}?"
          icon="ui-icon-alert" />
    </p:commandButton>
   </p:column>

我希望在删除确认消息中显示版本名称(您确定要删除版本“XYZ”吗?).. 但问题是版本名称“XYZ”不是显示在&lt;p:confirm&gt;的标题中,也没有在消息中;但它显示在&lt;p:commandButton&gt; 标题中。

我做错了什么?谢谢。


编辑:

我尝试修改commandButton并添加setPropertyActionListener

    <p:commandButton icon="ui-icon-close"
         title="Delete release #{release.name}"
         actionListener="#{releaseBean.deleteRelease(release)}"
         process="@this" update=":display :form2:releaseList">
         <f:setPropertyActionListener
         target="#{gestionReleaseBean.selectedRelease}"
         value="#{release}" />            
         <p:confirm
              header="Confirm deleting release #{release.name}"
              message="Are you really sure you want to delete release #{release.name}?"
              icon="ui-icon-alert" />
    </p:commandButton>

我在 bean 中添加了属性 selectedRelease,它是 getter/setter。

没用……

【问题讨论】:

  • commandButton 本身是否经过 ajax 更新,即 commandButton 的 update 属性是否包含嵌入它的组件的 id?
  • 更新涉及&lt;p:growl id="display"&gt; 和整个&lt;p:datatable&gt;(其中是按钮),以抑制新删除的行。为什么?
  • 是否可以使用带有 bean 属性的独立 dialogconfirmDialog 而不是带有全局 confirmDialogp:confirm
  • 似乎你偶然发现了一个可能的错误@Siho。我自己测试并确认过,&lt;p:confirm/&gt; 无法评估数据表的局部变量。它似乎只能评估页面构建期间可用的值,而不是页面渲染期间可用的值。这意味着只有在呈现数据表之前,支持 bean 中可用的值才会进入标记。您可以自己检查生成的 javascript,以确认负责弹出窗口本身的 js 具有空值,而您的 var 应该是
  • @rion18 怎么做,你的意思是这样(来自 PF 用户指南)&lt;h:form&gt; &lt;p:commandButton type="button" onclick="PF('cd').show()" /&gt; &lt;p:confirmDialog message="Are you sure about destroying the world?" header="Initiating destroy process" severity="alert" widgetVar="cd"&gt; &lt;p:commandButton value="Yes Sure" actionListener="#{buttonBean.destroyWorld}" update="messages" oncomplete="PF('cd').hide()"/&gt; &lt;p:commandButton value="Not Yet" onclick="PF('cd').hide();" type="button" /&gt; &lt;/p:confirmDialog&gt; &lt;/h:form&gt;

标签: jsf primefaces dialog confirm commandbutton


【解决方案1】:

如果你不介意一些额外的代码行,那么你可以如下实现,

首先在数据表外放置一个对话框

<p:dialog modal="true" header="Confirm" widgetVar="wgc" >
 <h:outputText id="msg" />
 <h:inputHidden id="idh" value="#{releaseBean.id}" />
 <p:commandButton value="Delete" action="#{bean.delete()}" />
 <p:commandButton value="Cancel" type="button" onclick="PF('wgc').hide()" />
</p:dialog>

在你的 javascript 部分添加这个

function confirm(id,name){
 document.getElementById('msg').innerHtml='Are you sure to delete ' +  name;
 document.getElementById('idh').value=id;
 PF('wgc').show();
}

然后在数据表中删除按钮

<p:commandButon type="button" 
                value="Delete" 
                onclick="confirm(#{release.id},'#{release.name}')" />

【讨论】:

  • 感谢 alessadro 的回复,但我没有 javascript 部分,我不知道将其放在我的 xhtml 页面的哪个位置。请您为我澄清一下这一点吗?
  • 你可以在你的xhtml页面的任何地方的标签中添加上面的代码,但是最好将js保持在body结束标签的上方跨度>
  • 别忘了在你的 bean 中实现 delete 方法,我只是向你展示了如何显示所选项目的名称并将 id 传递给 bean
  • "但是最好将 js 保持在正文结束标记的上方" ?怎么样??
  • 我的 xml 文件中有这个结构 --> ui:define>
猜你喜欢
  • 1970-01-01
  • 2016-02-06
  • 1970-01-01
  • 2023-03-04
  • 1970-01-01
  • 2015-02-14
  • 2016-08-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多