1
votes

I have a primefaces dialog which contains a Input text area and a command button "Submit".

I have a form which contains a button "Reject" and the form is inside a Tabview. When the user clicks the button "Reject", I display the dialog "rejectDialog" for the user to enter the reason for rejection. Once the user enters the comments and clicks the Submit button "submitButton" in the dialog an action method is called in the bean to update the comments value. I have a oncomplete attribute that calls a javascript method. After the action method is completed, the javascript method is never executed and dialog box is closed. The action executes successfully and I do not get any error. I also tried replacing oncomplete with onsuccess, but still the javascript method is never executed.

I would like to know why the javascript is never called in oncomplete inside a dialog?

I also tried adding just an alert in the oncomplete attribute, but still the alert is never executed.

The code is attached below.

XHTML Page

<p:dialog id="rejectDialog" header="Enter Comments" 
              hideEffect="explode" showEffect="explode" 
              resizable="false" widgetVar="rejectDlg" 
              style="background: #bcbcbc !important;"
              >
            <h:panelGrid columns="1" cellpadding="0" cellspacing="2"
                         styleClass="commentsPanel"
                         id="dialogpanelgrid">
                <p:outputLabel for="rejectComments" value="Enter Comments *: "
                               style="font-weight: bold;">

                </p:outputLabel>
                <p:inputTextarea cols="40" rows="4" autoResize="false" 
                   id="rejectComments" styleClass="rejectCommentsCls"
                   value="#{requestDetailsMB.rejectCommentsDesc}"
                   style="background: lightgray !important; color:#000 !important;" 
                                 widgetVar="txtreject"
                                 >
                    <f:validator validatorId="commentsValidator"></f:validator>
                </p:inputTextarea>
         <h:outputLabel id="rejectCommentsMessage" class="rejectCommentsMsg" value="" 
                               style="color:red !important; font-weight: bold;">

                </h:outputLabel>
            </h:panelGrid>
            <p:commandButton id="submitButton" 
                             style="margin-top: 15px; float:right;" 
                             value="Submit"
                             onclick="return validate();"
                             action="#{requestDetailsMB.rejectRequest}"
                             oncomplete="performRejectAction();"
                             /> 
    </p:dialog>
1

1 Answers

0
votes

I have run into issues before with placing javascript in the onclick event of a commandButton. The javascript can overwrite primefaces' behavior, which is probably why oncomplete is not being executed. I suggest that you use the onstart event instead:

<p:commandButton id="submitButton" 
    style="margin-top: 15px; float:right;" 
    value="Submit"
    onstart="return validate();"
    action="#{requestDetailsMB.rejectRequest}"
    oncomplete="performRejectAction();" />