1

我有一个带有两个对话框的表,一个用于删除,另一个用于添加新帐户。当我始终单击两个按钮时,会显示一个对话框。我做错了什么?这是我的前端代码

<ui:composition template="/WEB-INF/templates/default.xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">

<ui:param name="hideHeaderAndFooter" value="false" />
<ui:param name="navigationAndMain" value="false" />
<ui:param name="login" value="false" />

<ui:define name="mainContent">
    <div xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:p="http://primefaces.org/ui">
        <h:form id="form">
            <p:growl id="messages" showDetail="true" />
            <p:growl id="growl" showDetail="true" />
            <p:growl id="messageyesno" />
            <p:growl id="messageadd" />

            <p:dataTable var="account"
                value="#{accountManagedBeanTran.accountDataModel}"
                sortMode="multiple" paginator="true" rows="10"
                paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                rowsPerPageTemplate="5,10,15" editable="true"
                resizableColumns="true" draggableColumns="true"
                selection="#{accountManagedBeanTran.selectedAccounts}">

                <f:facet name="header">List of Users</f:facet>

                <p:ajax event="rowEdit" listener="#{accountManagedBeanTran.onEdit}"
                    update=":form:messages"></p:ajax>
                <p:ajax event="rowEditCancel"
                    listener="#{accountManagedBeanTran.onCancel}"
                    update=":form:messages"></p:ajax>
                <p:ajax event="colResize" update=":form:growl"
                    listener="#{accountManagedBeanTran.onResize}"></p:ajax>

                <p:column selectionMode="multiple" style="width:2%" />

                <p:column sortBy="#{account.username}" headerText="User Name"
                    filterBy="#{account.username}" filterMatchMode="contains"
                    style="width:30%">

                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{account.username}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{account.username}" style="width:100%" />
                        </f:facet>
                    </p:cellEditor>

                </p:column>

                <p:column sortBy="#{account.firstName}" headerText="First Name"
                    filterBy="#{account.firstName}" filterMatchMode="contains"
                    style="width:20%">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{account.firstName}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{account.firstName}" style="width:100%"
                                label="First Name" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column sortBy="#{account.lastName}" headerText="Surname"
                    filterBy="#{account.lastName}" filterMatchMode="contains">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{account.lastName}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{account.lastName}" style="width:100%"
                                label="Last Name" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column sortBy="#{account.email}" headerText="Email"
                    filterBy="#{account.email}" filterMatchMode="contains">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{account.email}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{account.email}" style="width:100%"
                                label="Email" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column style="width:6%">
                    <p:rowEditor />
                </p:column>

                <f:facet name="footer">

                    <div>

                        <p:commandButton id="delete" value="Delete"
                            onclick="confirmation.show()" type="button" />

                        <p:confirmDialog id="deleteConfirmDialog" message="Queres borrar el usuario?"
                            showEffect="drop" hideEffect="drop"
                            header="Delete" severity="alert"
                            widgetVar="confirmation" modal="true">

                            <p:commandButton value="Yes" update=":form:messageyesno"
                                oncomplete="confirmation.hide()"
                                actionListener="#{accountManagedBeanTran.onDelete}" />
                            <p:commandButton value="Not" onclick="confirmation.hide()"
                                type="button" />

                        </p:confirmDialog>

                        <p:commandButton id="add" value="Add"
                            onclick="confirmation.show()" type="button" />

                        <p:confirmDialog id="addConfirmDialog" message="Queres agregar un usuario?"
                            showEffect="drop" hideEffect="drop"
                            header="Add" severity="alert"
                            widgetVar="confirmation" modal="true">

                            <h:form id="messageAddForm">
                                <h:panelGrid columns="2" style="margin-bottom:10px">
                                    <h:outputLabel for="username" value="User Name:" />
                                    <p:inputText id="unsername" value="#{accountManagedBeanTran.newAccount.username}" />
                                    <h:outputLabel for="password" value="Password:" />
                                    <p:inputText id="password" value="#{accountManagedBeanTran.newAccount.password}" />
                                    <h:outputLabel for="firstName" value="First Name" />
                                    <p:inputText id="firstName" value="#{accountManagedBeanTran.newAccount.firstName}" />
                                    <h:outputLabel for="lastName" value="Surname" />
                                    <p:inputText id="lastName" value="#{accountManagedBeanTran.newAccount.lastName}" />
                                    <h:outputLabel for="email" value="Email" />
                                    <p:inputText id="email" value="#{accountManagedBeanTran.newAccount.email}" />
                                    <h:outputText value="Enabled:" />  
                                    <p:selectBooleanCheckbox value="#{accountManagedBeanTran.newAccount.enabled}" />            
                                </h:panelGrid>  
                            </h:form>

                            <p:commandButton value="Save" update=":form:messageadd"
                                oncomplete="confirmation.hide()"
                                actionListener="#{accountManagedBeanTran.onCreate}" />
                            <p:commandButton value="Cancel" onclick="confirmation.hide()"
                                type="button" />

                        </p:confirmDialog>
                                        </div>

                </f:facet>

            </p:dataTable>
        </h:form>
    </div>
</ui:define>

提前致谢。

4

1 回答 1

7

你的问题是你给你的两个对话框都一样widgetVar"confirmation")。每个对话框都必须是不同的widgetVar,并且您需要调用所需的对话框。

于 2013-08-16T00:41:21.340 回答