primefaces:如何设置动态 oncomplete 事件值,如 oncomplete="#backingbean.oncomplete"
primefaces: how to set dynamic oncomplete event value like oncomplete="#backingbean.oncomplete"
我想通过单个按钮显示不同的对话框取决于 backingbean 计算。就像显示消息 "Bill no has been paid already",如果客户输入重复的帐单号,如果帐单号没问题则显示 "Bill has been paid successfully"。我怎样才能做到这一点?
backingbean class:
private String oncomplete="";
public String getOncomplete() {
return oncomplete;
}
public void setOncomplete(String oncomplete) {
this.oncomplete = oncomplete;
}
public void bill_fees_calculation(){
if(bill_no=="wrong"){
oncomplete = "PF('wrongDialog').show()";
}
else{
oncomplete = "PF('rightDialog').show()";
}
}
在我的 xhtml 中:
<p:commandButton oncomplete="#{backingbean.bill_fees_calculation}" icon="ui-icon-search" title="View" update=""/>
<p:dialog header="Bill Info" widgetVar="wrongDialog" modal="false" showEffect="fade" hideEffect="explode" resizable="false" closable="true" closeOnEscape="true">
<p:outputPanel id="billDetail" autoUpdate="true" style="text-align:center;">
<p:panelGrid columns="2" columnClasses="label,value">
<h:outputText value="Output:" />
<h:outputText value="Bill no has been paid already" />
</p:panelGrid>
</p:outputPanel>
</p:dialog>
<p:dialog header="Bill Info" widgetVar="rightDialog" modal="false" showEffect="fade" hideEffect="explode" resizable="false" closable="true" closeOnEscape="true">
<p:outputPanel id="billDetail" autoUpdate="true" style="text-align:center;">
<p:panelGrid columns="2" columnClasses="label,value">
<h:outputText value="Output:" />
<h:outputText value="Bill no has been paid successfully" />
</p:panelGrid>
</p:outputPanel>
</p:dialog>
您可以使用 RequestContext#execute()
以编程方式声明应在当前 ajax 请求完成时执行的 JavaScript 代码。
public void billFeesCalculation() {
RequestContext requestContext = RequestContext.getCurrentInstance();
if ("wrong".equals(billNo)) {
requestContext.execute("PF('wrongDialog').show()");
}
else{
requestContext.execute("PF('rightDialog').show()");
}
}
请注意,我修复了原始代码段中的其他(severe)问题。
与具体问题无关,如果您只使用一个带有动态(面孔)消息的对话框,它会更干净并且 DRY 代码。
我想通过单个按钮显示不同的对话框取决于 backingbean 计算。就像显示消息 "Bill no has been paid already",如果客户输入重复的帐单号,如果帐单号没问题则显示 "Bill has been paid successfully"。我怎样才能做到这一点?
backingbean class:
private String oncomplete="";
public String getOncomplete() {
return oncomplete;
}
public void setOncomplete(String oncomplete) {
this.oncomplete = oncomplete;
}
public void bill_fees_calculation(){
if(bill_no=="wrong"){
oncomplete = "PF('wrongDialog').show()";
}
else{
oncomplete = "PF('rightDialog').show()";
}
}
在我的 xhtml 中:
<p:commandButton oncomplete="#{backingbean.bill_fees_calculation}" icon="ui-icon-search" title="View" update=""/>
<p:dialog header="Bill Info" widgetVar="wrongDialog" modal="false" showEffect="fade" hideEffect="explode" resizable="false" closable="true" closeOnEscape="true">
<p:outputPanel id="billDetail" autoUpdate="true" style="text-align:center;">
<p:panelGrid columns="2" columnClasses="label,value">
<h:outputText value="Output:" />
<h:outputText value="Bill no has been paid already" />
</p:panelGrid>
</p:outputPanel>
</p:dialog>
<p:dialog header="Bill Info" widgetVar="rightDialog" modal="false" showEffect="fade" hideEffect="explode" resizable="false" closable="true" closeOnEscape="true">
<p:outputPanel id="billDetail" autoUpdate="true" style="text-align:center;">
<p:panelGrid columns="2" columnClasses="label,value">
<h:outputText value="Output:" />
<h:outputText value="Bill no has been paid successfully" />
</p:panelGrid>
</p:outputPanel>
</p:dialog>
您可以使用 RequestContext#execute()
以编程方式声明应在当前 ajax 请求完成时执行的 JavaScript 代码。
public void billFeesCalculation() {
RequestContext requestContext = RequestContext.getCurrentInstance();
if ("wrong".equals(billNo)) {
requestContext.execute("PF('wrongDialog').show()");
}
else{
requestContext.execute("PF('rightDialog').show()");
}
}
请注意,我修复了原始代码段中的其他(severe)问题。
与具体问题无关,如果您只使用一个带有动态(面孔)消息的对话框,它会更干净并且 DRY 代码。