primefaces命令按钮条件语句 [英] primefaces commandbutton conditional statement

查看:107
本文介绍了primefaces命令按钮条件语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的命令按钮(Primefaces 6.0)中使用条件语句,如果我的java方法返回false或true,则该条件语句应显示一个对话框。像这样的东西:

I want a conditional statement in my commandbutton (Primefaces 6.0) which should show a dialog if my java method return false or true. Something like that:

<p:commandButton onclick="(myJavaMethod) ? deleteDialog.show() : confirmDialog.show()">
    <p:confirm header="Deleting Branch" message="Do you want to delete the Branch?"/>
</p:commandButton>   

myJavaMethod如果无法删除,则返回false;如果无法删除,则返回true我可以删除它。

myJavaMethod return false if i can't delete it and true if i can delete it.

我的对话框如下:

<!-- DELETE-DIALOG -->
<p:dialog id="deleteDialog" widgetVar="deleteDialog">
     <h:form id="deleteDialogForm">
        <h:panelGrid   columns="1" border="0">
        <p:outputLabel value="Branch could not be deleted"/>
            <p:commandButton icon="ui-icon-close" id="doCloseDialog" oncomplete="PF('deleteDialog').hide()" value="OK" class="btn-confirm"/>
       </h:panelGrid>
    </h:form>
</p:dialog>   

(与编辑对话框相同的对话框)

(Same Dialog with 'Edit' Dialog)

推荐答案

您要尝试的是使用 onclick 调用服务器端方法,而且您必须知道 onclick
只是一种客户端方法,您可以使用它来调用javascript方法,而javascript方法将调用 p:remoteCommand
这是一个简单的示例,但是我敢肯定,您可以在其他文章中找到更多关于该主题的信息,请阅读这篇文章,希望
能给您有关它的更多信息如何调用JSF仅在发生onclick事件时才支持bean的方法

What you are trying to do is to call a server side method with onclick, and you have to know that onclick is only a client side method, you can use it to call a javascript method and the javascript method will call a p:remoteCommand this is a simple example but i am pretty sure you can found more in other post to start about this topic read this post hope that will give more informations about it How to call JSF backing bean method only when onclick event occurs .

关于您的问题,您可以使用您的方法有条件地调用对话框

about your question you can use your method to conditionally call your dialog

让我们看这个示例:

ManagedBean.java

public void myJavaMethod () {
...
if( condition ){
RequestContext context = RequestContext.getCurrentInstance();
context.execute("PF('myDialogVar').show();"); 
} else {
RequestContext context = RequestContext.getCurrentInstance();
context.execute("PF('myDialogVarOther').show();");      
}    
...    
}

并在您的xhtml中

myXHTMLpage.xhtml

 <p:commandButton actionListener="#{managedBean.myJavaMethod}">
 ...
 </p:commandButton>

您可以在这篇文章中阅读更多内容从Managed Bean函数中调用Primefaces对话框

you can read more in this post Calling Primefaces dialog box from Managed Bean function.

希望对您有所帮助。

这篇关于primefaces命令按钮条件语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆