Daniel Szalay
Daniel Szalay

Reputation: 4101

PrimeFaces: which ajax event do I need?

I have this commandButton:

<p:commandButton value="View/Edit" onclick="bar.show()"
                 oncomplete="bar.hide(); dataSetUserDialog.show();"
                 actionListener="#{dataStoreBean.initUserLists}">
    <p:ajax event="?" update="userSelect" ></p:ajax>
    <f:param name="checkSum" value="#{dataSet.checkSum}" />
</p:commandButton>

And this dialog with a selectManyMenu inside:

<p:dialog header="View or Edit #{dataStoreBean.currentDataSetName} users"
          widgetVar="dataSetUserDialog" modal="true" width="500" height="200">
    <h:form>
        <p:selectManyMenu id="userSelect" value="#{dataStoreBean.selectedUsers}" style="width: 475px;">
            <f:selectItems value="#{dataStoreBean.users}"
                           var="user" itemValue="#{user.email}"
                           itemLabel="#{user.email} | #{user.groupName}" />
        </p:selectManyMenu>

        <p:commandButton value="Done"
                         actionListener="#{dataStoreBean.updateDataSetsUsers}"            
                         onclick="dataSetUserDialog.hide()" type="submit" />
    </h:form>

</p:dialog>

What I want to achieve is to have updated info in the dialog I want to show. userSelect is inside that dialog. So first I want #{dataStoreBean.initUserLists} to execute, and after that update (rerender) userSelect, and then show dataSetUserDialog. How can I do this?

Upvotes: 1

Views: 11285

Answers (1)

Daniel Szalay
Daniel Szalay

Reputation: 4101

As BalusC suggested, I should use action instead of actionListener:

<p:commandButton value="View/Edit users" onclick="loadNotification.show()"
                 oncomplete="loadNotification.hide(); dataSetUserDialog.show();"
                 action="#{dataStoreBean.initUserLists}" update="userSelect">
    <f:param name="checkSum" value="#{dataSet.checkSum}" />
    <f:param name="fullFileName" value="#{dataSet.fileName}.#{dataSet.fileType}" />
</p:commandButton>

<p:dialog id="userSelect" draggable="false" resizable="false"
          header="View or Edit #{dataStoreBean.currentDataSetName} users"
          widgetVar="dataSetUserDialog" modal="true" width="500" height="200">
    <h:form>
        <p:selectManyMenu value="#{dataStoreBean.selectedUsers}">
            <f:selectItems value="#{dataStoreBean.users}" var="user"
                           itemValue="#{user.email}"
                           itemLabel="#{user.email} | #{user.groupName}" />
        </p:selectManyMenu>

        <p:commandButton value="Done"
                         actionListener="#{dataStoreBean.updateDataSetsUsers}" 
                         update="dataSetMessages"
                         onclick="dataSetUserDialog.hide()" type="submit" />
    </h:form>
</p:dialog>

Upvotes: 3

Related Questions