本文介绍了primefaces命令按钮动作侦听器未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用primefaces 3.0jsf 2.0.
我已经准备好客户端主控,该向导使用向导添加客户端,并同时反映在数据表中.然后,我在数据表中更新了编辑实用程序.然后我在数据表中添加了删除按钮,并尝试调用bean的删除方法.
但是,当我单击删除"按钮时,将执行添加客户端的向导验证.因此,我创建了另一个文件ClientEditdatatable.xhtml并包含在clientmaster.xhtml中,但结果仍然相同.现在,我想在数据表中添加删除实用程序.我已经尝试了很多技巧来做到这一点.
我只想通过操作侦听器传递客户端ID,删除并刷新数据表,但命令按钮未执行方法.
好心的建议.我的代码如下:

I am using primefaces 3.0 and jsf 2.0.
I have prepared client master which add client using wizard and at the same time reflected in datatable. Then I have updated edit utility in datatable. Then I have added delete button in datatable and try call delete method of bean.
But when I click on delete button wizard validation for adding client is executed.So I have created another file ClientEditdatatable.xhtml and included in clientmaster.xhtmlbut same result remain.Now I want to add delete utility in datatable. I have tried many tricks to do it.
I just want to pass client id through action listener,get deleted and refresh datatable but command button not executing method.
Kindly advice.My code as below:

ClientMaster.xhtml

<h:body>
    <ui:composition template="/template/mainLayout.xhtml" >
        <ui:define name="pageContent">
            <h:form id="cm">
                <p:growl life="5000" showDetail="true" showSummary="true" id="mymessage" autoUpdate="true"/>
                <br/>
                user id :#{sessionScope.USER_ID};
                <br/>
                <p:wizard widgetVar="wiz" flowListener="#{clientUitility.onFlowProcess}" showNavBar="true"  >
                    <p:tab id="personal" title="Personal" >
                        <p:panel id="personal1" header="Personal Details">
                            <!-- <h:messages errorClass="error"/> -->
                            <h:panelGrid columns="6" styleClass="grid">
                                <h:outputText value="First Name:*" />
                                <p:inputText required="true" label="FirstName"
                                             value="#{clientUitility.client.firstName}" >
                                </p:inputText>

                                <h:outputText value="Middle Name:*" />
                                <p:inputText required="true" label="MidddleName"
                                             value="#{clientUitility.client.middleName}" />

                                <h:outputText value="Last Name:*" />
                                <p:inputText required="true" label="LastName"
                                             value="#{clientUitility.client.lastName}" />

                                <h:outputText value="Login ID:* " />
                                <p:inputText required="true" label="LoginID"
                                             value="#{clientUitility.client.loginID}"/>

                                <h:outputText value="Password:* " />
                                <p:inputText required="true" label="Password"
                                             value="#{clientUitility.client.password}"/>
                            </h:panelGrid>
                        </p:panel>
                    </p:tab>
                    <p:tab id="address" title="Address" >
                        <p:panel id="address1" header="Adress Details">
                            <!-- <h:messages errorClass="error"/> -->
                            <h:panelGrid columns="6" styleClass="grid">
                                <h:outputText value="Address:*" />
                                <p:inputText required="true" label="Address1"
                                             value="#{clientUitility.client.address1}" />
                                <h:outputText />
                                <p:inputText label="Address2"
                                             value="#{clientUitility.client.address2}" />
                                <h:outputText />
                                <p:inputText label="Address3"
                                             value="#{clientUitility.client.address3}" />
                                <h:outputText value="City:* " />
                                <p:inputText required="true" label="City"
                                             value="#{clientUitility.client.city}" />

                                <h:outputText value="Pincode:* " />
                                <p:inputText required="true" label="Pincode"
                                             value="#{clientUitility.client.pincode}" />
                                <h:outputText value="State:* " />
                                <p:inputText required="true" label="State"
                                             value="#{clientUitility.client.state}" />
                            </h:panelGrid>
                        </p:panel>
                    </p:tab>
                    <p:tab id="contact" title="Contact" >
                        <p:panel id="contact1" header="Contact Information">
                            <!-- <h:messages errorClass="error"/> -->
                            <p:panelGrid columns="4" styleClass="grid">
                                <h:outputText value="Mobile:* " />
                                <p:inputText required="true" label="MobileNo"
                                             value="#{clientUitility.client.mobileNo}" />
                                <h:outputText value="Email ID: "/>
                                <p:inputText label="EmailID"
                                             value="#{clientUitility.client.emailID}" />
                                <h:outputText value="STD Code: "/>
                                <p:inputText label="STDCode"
                                             value="#{clientUitility.client.stdCode}" />
                                <h:outputText value="Phone No: "/>
                                <p:inputText label="PhoneNo"
                                             value="#{clientUitility.client.phoneNo}" />                                </p:panelGrid>
                        </p:panel>
                    </p:tab>

                    <p:tab id="confirm" title="Confirmation" >
                        <p:panel id="confirm1" header="Confirm and Submit">

                            <h:panelGrid  columns="6" styleClass="grid" >

                                <h:outputText value="First Name: " />
                                <h:outputText styleClass="outputLabel"
                                              value="#{clientUitility.client.firstName}" />
                                <h:outputText value="Middle Name: " />
                                <h:outputText styleClass="outputLabel"
                                              value="#{clientUitility.client.middleName}" />
                                <h:outputText value="Last Name: " />
                                <h:outputText styleClass="outputLabel"
                                              value="#{clientUitility.client.lastName}" />
                                <h:outputText value="Login ID: " />
                                <h:outputText styleClass="outputLabel"
                                              value="#{clientUitility.client.loginID}"/>
                                <h:outputText value="Password: " />
                                <h:outputText styleClass="outputLabel"
                                             value="#{clientUitility.client.password}"/>
                                <h:outputText/>
                                <h:outputText/>
                                <h:outputText value="Address: " />
                                <h:outputText styleClass="outputLabel"
                                              value="#{clientUitility.client.address1}" />
                                <h:outputText />
                                <h:outputText styleClass="outputLabel"
                                              value="#{clientUitility.client.address2}" />
                                <h:outputText />
                                <h:outputText styleClass="outputLabel"
                                              value="#{clientUitility.client.address3}" />
                                <h:outputText value="City: " />
                                <h:outputText styleClass="outputLabel"
                                              value="#{clientUitility.client.city}" />
                                <h:outputText value="State: " />
                                <h:outputText styleClass="outputLabel"
                                              value="#{clientUitility.client.state}" />
                                <h:outputText value="Pincode: " />
                                <h:outputText styleClass="outputLabel"
                                              value="#{clientUitility.client.pincode}" />
                                <h:outputText value="Email ID: " />
                                <h:outputText styleClass="outputLabel"
                                              value="#{clientUitility.client.emailID}" />
                                <p:commandButton id="addClient" immediate="true" value="Add Client" actionListener="#{clientUitility.save}" oncomplete="wiz.loadStep (wiz.cfg.steps [0], true)" update="@parent,:cm:clientList"> <!-- update="@parent,:cm:clientList" -->
                                </p:commandButton>
                            </h:panelGrid>
                        </p:panel>
                    </p:tab>
                </p:wizard>
                <ui:include id="ce" src="ClientEditDatatable.xhtml"/>
            </h:form>
        </ui:define>
    </ui:composition>
</h:body>

ClientEditDatatable.xhtml

ClientEditDatatable.xhtml

<h:body>
     <h:form id="fce">
        <p:confirmDialog message="Delete client?" severity="alert" widgetVar="confirmDeleteClient" visible="false" appendToBody="true">
            <p:commandButton value="Yes" update=":cm:fce:clientList" oncomplete="confirmDeleteClient.hide()" actionListener="#{clientUitility.deleteRecord}" >
            </p:commandButton>
            <p:commandButton value="No" onclick="confirmDeleteClient.hide()" type="button" />
        </p:confirmDialog>
        <p:dataTable var="client" value="#{clientUitility.clientAll}" id="clientList" editable="true"
                     rowKey="#{client.clientID}" paginator="true" rows="10" rowsPerPageTemplate="10,15,20">
            <p:column headerText="First Name" style="width:125px" filterBy="#{user.firstname}" sortBy="#{client.firstName}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.firstName}" />
                    </f:facet>
                    <f:facet name="input">
                        <h:outputText value="#{client.firstName}" />
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="Middle Name" style="width:125px" filterBy="#{client.middleName}" sortBy="#{client.middleName}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.middleName}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.middleName}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>

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

            <p:column headerText="Login ID" style="width:125px" filterBy="#{client.loginID}" sortBy="#{client.loginID}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.loginID}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.loginID}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Password" style="width:125px" filterBy="#{client.password}" sortBy="#{client.password}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.password}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.password}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="Address1" style="width:125px" filterBy="#{client.address1}" sortBy="#{client.address1}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.address1}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.address1}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="Address2" style="width:125px" filterBy="#{client.address2}" sortBy="#{client.address2}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.address2}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.address2}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="Address3" style="width:125px" filterBy="#{client.address3}" sortBy="#{client.address3}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.address3}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.address3}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="City" style="width:125px" filterBy="#{client.city}" sortBy="#{client.city}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.city}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.city}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="State" style="width:125px" filterBy="#{client.state}" sortBy="#{client.state}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.state}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.state}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="Pincode" style="width:125px" filterBy="#{client.pincode}" sortBy="#{client.pincode}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.pincode}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.pincode}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="Mobile No" style="width:125px" filterBy="#{client.mobileNo}" sortBy="#{client.mobileNo}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.mobileNo}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.mobileNo}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="STD Code" style="width:125px" filterBy="#{client.stdCode}" sortBy="#{client.stdCode}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.stdCode}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.stdCode}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="Phone No" style="width:125px" filterBy="#{client.phoneNo}" sortBy="#{client.phoneNo}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.phoneNo}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.phoneNo}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="Email ID" style="width:125px" filterBy="#{client.emailID}" sortBy="#{client.emailID}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.emailID}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{client.emailID}" style="width:100%" >
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="Edit" style="width:50px">
                <p:rowEditor />
            </p:column>
            <p:ajax event="rowEdit" listener="#{clientUitility.editRowListner}" update=":cm:mymessage"/>

            <p:column headerText="Delete" style="width:50px">
                <p:commandButton id="deleteClient" value="Delete" onclick="confirmDeleteClient.show()" title="Delete this Client" styleClass="ui-icon-closethick">
                </p:commandButton>
            </p:column>
        </p:dataTable>
    </h:form>
</h:body>

clientUtility.java

clientUtility.java

@ManagedBean
@ViewScoped
public class ClientUitility {
private ClientBean client = new ClientBean();
private List<ClientBean> clientAll = new ArrayList<ClientBean>();
/** Creates a new instance of ClientUitility */
public ClientUitility() {
    clientAll = new ArrayList<ClientBean>();
    int userID = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString());
    clientAll = ClientService.GenerateClientList(userID);
}
public List<ClientBean> getClientAll() {
    return clientAll;
}
public void setClientAll(List<ClientBean> clientAll) {
    this.clientAll = clientAll;
}
public ClientBean getClient() {
    return client;
}
public void setClient(ClientBean client) {
    this.client = client;
}
public String onFlowProcess(FlowEvent event) {
    System.out.println("Current wizard step:" + event.getOldStep());
    System.out.println("Next step:" + event.getNewStep());
    System.out.println("First name : " + client.getfirstName());
    System.out.println("Last name : " + client.getlastName());
    System.out.println("Age name : " + client.getloginID());
    return event.getNewStep();
}
public void editRowListner(RowEditEvent rowEditEvent) {
    try {
        ClientBean updatedClient = (ClientBean) rowEditEvent.getObject();
        System.out.println("Client First Name: " + updatedClient.getfirstName());
        ClientService.EditClient(updatedClient);
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("Updated", updatedClient.getfirstName() + " " + updatedClient.getlastName()));
    } catch (Exception e) {
        e.getMessage();
    }
}
public void deleteRecord(ActionEvent actionEvent) {
    try {
        //System.out.println("Client ID: " + actionEvent.getComponent().getAttributes().get("cID").toString());
        System.out.println("delete client of User ID: " + FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString());
        FacesMessage msg = new FacesMessage("Client Deleted", "");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
public void save(ActionEvent actionEvent) {        client.setuserID(Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString()));
    System.out.println("Client ID : " + client.getclientID());
    System.out.println("User ID : " + client.getuserID());
    ClientService.AddClient(client);
    client = new ClientBean();
    clientAll = ClientService.GenerateClientList(Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString()));
    FacesMessage msg = new FacesMessage("Client Created", "");
    FacesContext.getCurrentInstance().addMessage(null, msg);
}
}

请忠告我要去哪里?

推荐答案

您不能也不应嵌套表格.

You can't and shouldn't nest forms.

ClientMaster.xhtml中,替换

            <ui:include id="ce" src="ClientEditDatatable.xhtml"/>
        </h:form>

作者

        </h:form>
        <ui:include id="ce" src="ClientEditDatatable.xhtml"/>

另请参见:

08-14 05:51