primefaces 命令按钮条件语句
primefaces commandbutton conditional statement
我想要在我的命令按钮 (Primefaces 6.0) 中有一个条件语句,如果我的 java 方法 return 为假或真,它应该显示一个对话框。类似的东西:
<p:commandButton onclick="(myJavaMethod) ? deleteDialog.show() : confirmDialog.show()">
<p:confirm header="Deleting Branch" message="Do you want to delete the Branch?"/>
</p:commandButton>
myJavaMethod return 如果我不能删除它则为 false,如果我可以删除它则为 true。
我的对话框如下所示:
<!-- 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>
(与 'Edit' 对话框相同的对话框)
您要做的是使用 onclick
调用服务器端方法,并且您必须知道 onclick
只是一个客户端方法,您可以使用它来调用 javascript 方法,而 javascript 方法将调用 p:remoteCommand
这是一个简单的示例,但我很确定您可以在其他 post 中找到更多内容来开始这个主题阅读此 post 希望会
提供有关它的更多信息 How to call JSF backing bean method only when onclick event occurs 。
关于您的问题,您可以使用您的方法有条件地调用您的对话框
让我们看这个例子:
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>
您可以在此 post Calling Primefaces dialog box from Managed Bean function 中阅读更多内容。
希望对您有所帮助。
我想要在我的命令按钮 (Primefaces 6.0) 中有一个条件语句,如果我的 java 方法 return 为假或真,它应该显示一个对话框。类似的东西:
<p:commandButton onclick="(myJavaMethod) ? deleteDialog.show() : confirmDialog.show()">
<p:confirm header="Deleting Branch" message="Do you want to delete the Branch?"/>
</p:commandButton>
myJavaMethod return 如果我不能删除它则为 false,如果我可以删除它则为 true。
我的对话框如下所示:
<!-- 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>
(与 'Edit' 对话框相同的对话框)
您要做的是使用 onclick
调用服务器端方法,并且您必须知道 onclick
只是一个客户端方法,您可以使用它来调用 javascript 方法,而 javascript 方法将调用 p:remoteCommand
这是一个简单的示例,但我很确定您可以在其他 post 中找到更多内容来开始这个主题阅读此 post 希望会
提供有关它的更多信息 How to call JSF backing bean method only when onclick event occurs 。
关于您的问题,您可以使用您的方法有条件地调用您的对话框
让我们看这个例子:
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>
您可以在此 post Calling Primefaces dialog box from Managed Bean function 中阅读更多内容。
希望对您有所帮助。