0

I have a relatively simple datatable that contains a list of requests. I have command buttons for approval and rejection and a messages section at top to provide feedback.

For the approvals I simply process everything and refresh the datatable and message but for rejections I want to prompt the user for a message. No matter what I seem to do I cannot have both the datatable update and the message show when the dialog closes. The best I could achieve was for the message to appear for a few milliseconds whilst the dialog was closing.

so my page starts with the messages and a form and a datatable

   <h:form id="form">

      <p:messages id="messages" showDetail="true" closable="true">
         <p:autoUpdate />
      </p:messages>

      <p:dataTable id="dtReqs" allowUnsorting="true" sortMode="single" value="#{myBean.openRequests}" var="req">

then I have a command button to process the rejections

<p:column headerText="Reject" width="60">
    <p:commandButton icon="pi pi-times" styleClass="rounded-button ui-button-danger"
               oncomplete="PF('rejectDlg').show()">
        <f:setPropertyActionListener value="#{req}" target="#{myBean.selectedRequest}" />
    </p:commandButton>
</p:column>

and finally a dialog to get the user input

<p:dialog id="inputDialog" widgetVar="rejectDlg" header="Enter Rejection Explanation" modal="true">         
    <p:ajax event="close" update=":form:dtReqs" />
    <p>Please enter a reason for rejection</p>
    <p:inputTextarea id="rejectReasonText" rows="5" cols="60" value="#{myBean.userMessage}" />
    <br /> <br />
    <p:commandButton value="Reject" action="#{myBean.processRejection}"
           icon="pi pi-times" styleClass="ui-button-danger" />
    <p:commandButton value="Cancel" onclick="PF('rejectDlg').hide()" />      
</p:dialog>

the ViewScoped baking bean then has

public void procesRejection() {
  //handle updates and update variables

  FacesMessage msg = new FacesMessage("Title", "Content");
  FacesContext.getCurrentInstance().addMessage(null, msg);

}

With code as is when you click the reject button on the dialog it does all the processing it needs to do (and works fine) and the message is displayed behind the dialog but the form doesn't get closed and the datatable is only updated when you click cancel or the x to close the dialog.

I have tried adding oncomplete on the reject button to close the form and whilst this works and updates the datatable, the message flashes up for a millisecond and then vanished along with the form. I have tried closing the form in the processRejection method which achieves the same result.

Removing the ajax close event and adding oncomplete to the reject button to close the dialog closes the dialog and displays the message but doesn't refresh the datatable.

How can I achieve what I want in prompting the user for some text and then

  • Close Dialog
  • Refresh datatable
  • Display message
Jameson_uk
  • 432
  • 2
  • 12
  • Have a look at https://stackoverflow.com/questions/9195756/keep-pdialog-open-when-a-validation-error-occurs-after-submit – Jasper de Vries Jun 29 '21 at 11:02
  • That appears to be the other way around in that they want to display a message and not close the form (which I have now but isn't what I want....) Unless I have missed something I can't see how I can apply that here?? I have already tried closing the form within the procesesRejection method which displays the message only until the dialog is closed. – Jameson_uk Jun 29 '21 at 15:07
  • Follow that post and also convert your action(that refresh the entire page) into an actionListener(with only the needed update) and you should get what you need – WoAiNii Jun 29 '21 at 20:58

0 Answers0