Steve
Steve

Reputation: 31

PrimeFaces confirmdialogs from single Bean

Submit button is pressed the bean first checks for valid values, if it fails validation a dialog is presented. While the process is running another session submits a button press and the bean checks the flag and need to present a different dialog.

Is there away to have a single commandButton interact with two different confirmDialogs, commandButton "update" interacts with the confirmDialog

The main difference with my issue verse the other examples/solutions, there is only one button. And the update="confirmValid" on the submit button is only working for the first button push.

The bean is called successfully from "second" button press, the forceRequest method doesn't display the dialog

<p:commandButton id="myButton" update="confirmValid growl"
                 value="Submit"
                 actionlistener="#{message.sendMessage}"
...
/>

This dialog is presented for display when the request is invalid

<p:confirmDialog header="#{message.invalidValuesHdr}"
   id="confirmValidData" message="#{message.invalid}"
   wigdetVar="confirmValidData">
    <p:commandButton value="Ok" update="growl" oncomplete="PF('confirmValidData').hide()"
</p:confirmDialog>

This dialog is presented when the process flag has been updated

<p:confirmDialog header="#{message.forceRequestHdr}"
   id="confirmValidData" message="#{message.invalid}"
   wigdetVar="confirmForce">
    <p:commandButton value="Ok" update="growl" oncomplete="PF('confirmForce').hide()"
</p:confirmDialog> 

Bean:

@ViewScoped 

@Override 
public void sendMessage() {
  if (....)
    forceRequest();

}

public void forceRequest(){
   FacesMessage message = new 
   FacesMessage(FacesMessage.SEVERITY_INFO,"Message Title", "Message body");
   RequestContext.getCurrentInstance().showMessageInDialog(message);
}

Displays a dialog the method below does nothing, which is the issue

public void forceRequest(){
  RequestContext context = RequestContext.getCurrentInstance();
  context.openDialog("Confirm");
  context.execute("PF('confirmForce').jq.click();");
}

faces-config.xml is updated

Upvotes: 0

Views: 303

Answers (1)

Steve
Steve

Reputation: 31

public void forceRequest(){
  RequestContext.getCurrentInstance().execute("PF('confirmForce').show();");
}

Above was the solution and now on to the bean

Upvotes: 0

Related Questions