Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

primefaces commandbutton actionlistener not called

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

<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

@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);
}
}

Kindly advice where am I mistaking?

like image 911
mathaker Avatar asked Jun 01 '12 10:06

mathaker


1 Answers

You can't and shouldn't nest forms.

In the ClientMaster.xhtml, replace

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

by

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

See also:

  • commandButton/commandLink/ajax action/listener method not invoked or input value not updated
like image 58
BalusC Avatar answered Oct 03 '22 05:10

BalusC