zyydoosh
zyydoosh

Reputation: 379

oncomplete with commandButton isn't working

I have a nested datatable that has an Edit command button, that shows a dialog modal,

<p:commandButton value="Edit" oncomplete="PF('editStudy').show()" type="button">
                <p:ajax event="click" listener="#{queryStudiesBean.setRenderDialog(true)}" update="editDialogStudy" />
                <p:ajax event="click" listener="#{queryStudiesBean.setEditableStudyIndex(studyIndex)}" update="editDialogStudy: />
                <p:ajax event="click" listener="#{queryStudiesBean.setEditablePatientIndex(patientIndex)}" update="editDialogStudy" />
</p:commandButton>

I was fixing the issue of keeping the rows of the child datatable expanded after updating, I was following this answer , but I faced another problem that once I load the datatable page, even before I click on the Edit button, the dialog commandButton that has the update attribute gets evaluated,

<p:commandButton process="@form" update="@form,:form2:patient-dt:#{queryStudiesBean.editablePatientIndex}:study-dt" action="#{queryStudiesBean.updateStudy()}" oncomplete="PF('editStudy').hide()" value="Save" styleClass="fixed-button-size" />

, this gives null error as patientIndex is still null, as I didn't even click on the edit button of the datatable to set the patientIndex.

So I managed to solve this by adding rendered="#{queryStudiesBean.renderDialog}" attribute to the dialog.

Now I have difficulties setting this boolean to true in the edit button action, the dialog doesn't shows right now, in the above code, I used oncomplete, and set the boolean value in <p:ajax> (as both action attribute, and <f:setPropertyActionListener> doesn't work for me, I was thinking that the boolean will be set to true before the oncomplete gets called, so the dialog shows, but this is not happend, can someone explains to me why? I saw alots of posts but no one worked for me.

full datatable code

full dialog code

I'm using: primefaces 6.2, java8

Upvotes: 0

Views: 739

Answers (1)

Holger
Holger

Reputation: 919

If your update="@form,:form2:patient-dt:#{queryStudiesBean.editablePatientIndex}:study-dt references parentIndex, it will already been called when the button is rendered.

  1. Your update="editDialogStudy" needs to be update=":editDialogStudy" because it's inside a row of a datatable.

  2. You update the form, but the rendered is outside the form, so it won't be updated. Put a <h:panelGroup... around the dialog and update the panelGroup

Upvotes: 1

Related Questions