Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 基于bean中的值在PrimeFaces中显示对话框_Jsf 2_Primefaces - Fatal编程技术网

Jsf 2 基于bean中的值在PrimeFaces中显示对话框

Jsf 2 基于bean中的值在PrimeFaces中显示对话框,jsf-2,primefaces,Jsf 2,Primefaces,我有一个p:dialog,它通过命令按钮的oncomplete显示 <p:commandButton value="Update" id="update" actionListener="#{serviceTypeViewBean.beforeUpdate}" oncomplete="updatedlg.show();)"> </p:commandButton> 如何在commandButton的oncomplete中添加此条件?您可以使用EL求值来呈现

我有一个
p:dialog
,它通过命令按钮的
oncomplete
显示

<p:commandButton value="Update" id="update"
    actionListener="#{serviceTypeViewBean.beforeUpdate}"
    oncomplete="updatedlg.show();)">
</p:commandButton>

如何在commandButton的oncomplete中添加此条件?

您可以使用EL求值来呈现/隐藏javascript代码:

oncomplete=#{不是空的serviceTypeViewBean.list?'updatedlg.show()':''}

另请参见:


你可以按照@Xtreme Biker的建议来做。另一种解决方案是使用callbackParam:

在更新之前向您的
方法代码添加如下内容:

if(list != empty){
   RequestContext.getCurrentInstance().addCallbackParam("emptyList", false);
} else {
   RequestContext.getCurrentInstance().addCallbackParam("emptyList", true);
}
然后可以在
oncomplete
属性中检查参数,如下所示:

<p:commandButton value="Update" id="update"
    actionListener="#{serviceTypeViewBean.beforeUpdate}"
    oncomplete="if(!args.emptyList) { PF('updatedlg').show(); }">
</p:commandButton>

请注意callbackParam是灵活的,您可以在许多情况下找到它的用法

<p:commandButton value="Update" id="update"
    actionListener="#{serviceTypeViewBean.beforeUpdate}"
    oncomplete="if(!args.emptyList) { PF('updatedlg').show(); }">
</p:commandButton>