displaying a listbox after dialog confirm

scofield Source

i have a datatable of users which contains a column with a delete button. what i want is when i click on the button a confirm dialog shows up and ask for confirmation. after the confirmation i want to check a condition if it's true another dialog shows up containig a listbox. this is my view.xhtml:

<h:form id="form">
    <p:dataTable value="#{PersonnelMB.lstp}" var="h" resizableColumns="true" id="pdt" paginator="true" rows="10" widgetVar="ptable">
    <f:facet name="header">
        <p:outputPanel style="align-content: right:all;">
            <h:outputText value="Recherche:" />
            <p:inputText id="globalFilter" onkeyup="PF('ptable').filter();" style="width:150px;height: 28px;" placeholder="Enter keyword"/>
        </p:outputPanel>
    </f:facet>
    <p:column sortBy="#{h.id}" filterBy="#{h.id}" style="text-align: center;">
        <f:facet name="header">
            <h:outputText value="Id"></h:outputText>
        </f:facet>
        <h:outputText value="#{h.id}"></h:outputText>
    </p:column>
    <p:column sortBy="#{h.prenom}" filterBy="#{h.prenom}" style="text-align: center">
        <f:facet name="header">
            <h:outputText value="Prenom"></h:outputText>
        </f:facet>
        <h:outputText value="#{h.prenom}"></h:outputText>
    </p:column>
    <p:column sortBy="#{h.nom}" filterBy="#{h.nom}" style="text-align: center">
        <f:facet name="header">
            <h:outputText value="Nom"></h:outputText>
        </f:facet>
        <h:outputText value="#{h.nom}"></h:outputText>
    </p:column>
    <p:column filterBy="#{h.email}" >
        <f:facet name="header">
            <h:outputText value="Email"></h:outputText><br/>
        </f:facet>
        <h:outputText value="#{h.email}"></h:outputText>
    </p:column>
    <p:column  >
        <f:facet name="header">
            <h:outputText value="Actions"></h:outputText>
        </f:facet>
        <p:commandButton type="button" icon="ui-icon-trash" style="background-color:#f20d0d;" onclick="confirmation.show()"/>
        <p:confirmDialog message="Are you sure?" header="Confirmation" severity="alert" widgetVar="confirmation">
          <p:commandButton value="Yes" oncomplete="confirmation.hide()"  actionListener="#{PersonnelMB.supprimerPerso}" />
          <p:commandButton value="Not" onclick="confirmation.hide()" type="button" />
        </p:confirmDialog>

    </p:dataTable>

jsfprimefaces

Answers

answered 6 months ago VaazhgaV #1

You can call another dialog (lets suppose its widgetVar="anotherDialog") from your managed bean like this:

    public void supprimerPerso() {
    ...
    if (condition) {
        RequestContext requestContext = RequestContext.getCurrentInstance();
        requestContext.execute("PF('anotherDialog').show()");
    }
}

Note: 1. If you do not pass any parameters to the above method, remember to add braces to method call : actionListener="#{PersonnelMB.supprimerPerso () }". Braces are omitted when parameters are passed. 2. Enable selection and use the selected record for deletion. This makes it easier.

Check showcase for showing listbox in "anotherDialog". Something like this:

<p:dialog header="Selected User for Deletion" widgetVar="anotherDialog" modal="true" showEffect="fade"  resizable="false">
    <p:panelGrid columns="2" id="display" columnClasses="label,output">
        <h:outputText value="Employee ID:" />
        <h:outputText value="#{PersonnelMB.selectedUser.id}" />

        <h:outputText value="Employee Name:" />
        <h:outputText value="#{PersonnelMB.selectedUser.nom}" />

    </p:panelGrid>
</p:dialog>

comments powered by Disqus