0

I would like to show different dialog from a single button depends on backingbean calculation. Like show a msg "Bill no has been paid already", if client enter a duplicate bill no, if the bill no is ok than shows like "Bill has been paid successfully". How can I achieve this?

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()"; 
    }
}

In my 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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

3

You can use RequestContext#execute() to programmatically declare JavaScript code which should be executed on complete of the current ajax request.

public void billFeesCalculation() {
    RequestContext requestContext = RequestContext.getCurrentInstance();

    if ("wrong".equals(billNo)) {
        requestContext.execute("PF('wrongDialog').show()");
    }
    else{
        requestContext.execute("PF('rightDialog').show()");
    }
}

Note that I fixed other (severe) issues in the original snippet.


Unrelated to the concrete problem, it would be more clean and DRY code if you used only one dialog with a dynamic (faces) message.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555