2013-10-14 165 views
3

我想要添加确认对话框befor编辑行或如何提示用户确认befor任何操作。 哪个对话框应该用于下面的代码。如何添加确认对话框

<h:commandLink value="EditPage" action="#{countryBean.editCountryByCountryCode(true)}" class="edit_icon" > 
      <f:setPropertyActionListener target="#{countryBean.editCountryId}" value="#{countryLang.countryCode}" /> 
      </h:commandLink> 

回答

15

一个简单的方法,采用了简单的JavaScript:

<h:commandLink onclick="if (! confirm('Really want to do that?')) return false" 
value="EditPage" action="#{countryBean.editCountryByCountryCode(true)}" class="edit_icon" > 
    <f:setPropertyActionListener target="#{countryBean.editCountryId}" value="#{countryLang.countryCode}" /> 
</h:commandLink> 
+0

这是一种魅力。谢谢。 –

+2

较短的“return confirm('真的想这样做?')”也是正确的。 – snorbi

2

可以使用Primefaces确认用于此目的的对话<p:confirm/>。你可以找到示例展示here

+0

但适用于号码:命令按钮only..canü提供用于h例子:commandLink可以是其他然后primeface。 – Surya

+0

如果您不想使用'primefaces',那么您可以随时选择使用'JQuery',如果您熟悉这一点的话。 – SRy

+0

PF 5+也可以使用commandLink – Anton