2015-05-06 29 views
0

我想显示不同的对话框从一个单一的按钮取决于backingbean计算。如显示一个味精“如果已经支付账单”,如果客户输入一个重复的账单号码,如果账单号码比“账单已经支付成功”这样的显示好。我怎样才能做到这一点?primefaces:如何设置动态oncomplete事件值,如oncomplete =“#backingbean.oncomplete”

backingbean类:

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> 

回答

3

您可以使用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代码。