Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8106453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:28:20+00:00 2026-06-06T00:28:20+00:00

I am working in primefaces 3.3 and jsf 2.0. I have problem in deleting

  • 0

I am working in primefaces 3.3 and jsf 2.0. I have problem in deleting record in lazy datamodel. As sorting and filtering is not working properly in datatable I had to use lazydatamodel concept.Now save(through wizard), edit,sorting and filtering are working fine. When I tried to delete record from datatable, dialog is appearing and when I click on yes(command button) to delete record, instead of calling bean method control goes to load method of lazy data model. deleterecord of clientUitility.java(managedbean) not calling. can anyone give me guidance to delete record from datatable by passing client object
Here is code snippet

clientMaster.xhtml

 <h:form id="cm">
                <p:growl life="5000" showDetail="true" showSummary="true" id="mymessage" />
                <p:wizard widgetVar="wiz" flowListener="#{clientUitility.onFlowProcess}" showNavBar="true" >
                    <p:tab id="personal" title="Personal" >
.....
.....// tab and columns
.....

                                        <p:commandButton id="addClient" immediate="true" value="Add Client" actionListener="#{clientUitility.save}" oncomplete="wiz.loadStep (wiz.cfg.steps [0], true)" update=":fce:clientList" > <!-- update="@parent,:cm:clientList" -->
                                        </p:commandButton>
                                    </p:column>
                                </p:row>
                            </p:panelGrid>
                        </p:panel>
                    </p:tab>
                </p:wizard>
            </h:form>
            <ui:include id="ce" src="ClientEditDatatable.xhtml"/>

ClientEditdatatable.xhtml

<h:form id="fce">


        <p:dataTable var="client" value="#{clientUitility.lazyModel}" id="clientList" editable="true" widgetVar="clientTable" rowKey="#{client.clientID}"
                     paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                     paginator="true" rows="10" rowsPerPageTemplate="5,10,15" lazy="true">

            <p:column headerText="First Name" style="width:100px" filterBy="#{client.firstName}" sortBy="#{client.firstName}" >
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{client.firstName}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText id="dtFirstName" value="#{client.firstName}" style="width:100%" label="FirstName" onkeyup="valid(this)" onblur="convertUpper(this.id)"  >
                            <f:validateLength for="dtFirstName" maximum="100" minimum="3"/>
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
.....
..... // code of 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-trash">
                    <f:setPropertyActionListener target="#{client}" value="#{clientUitility.client}"/>
                </p:commandButton>
            </p:column>
        </p:dataTable>
        <p:confirmDialog message="Delete client?" severity="alert" widgetVar="confirmDeleteClient" visible="false" appendToBody="true" >
            <p:commandButton value="Yes" update="clientList" immediate="true" oncomplete="confirmDeleteClient.hide()" actionListener="#{clientUitility.deleteRecord}" >
<f:setPropertyActionListener target="#{client}" value="#{client}"
            </p:commandButton>
            <p:commandButton value="No" onclick="confirmDeleteClient.hide()" type="button" />
        </p:confirmDialog>
        <br/>

LazyClientDataModel.java

public class LazyClientDataModel extends LazyDataModel<ClientBean> {
private List<ClientBean> datasource;
public LazyClientDataModel(List<ClientBean> datasource) {
    this.datasource = datasource;
}
@Override
public ClientBean getRowData(String rowKey) {
    for(ClientBean client : datasource) {
        if(Integer.toString(client.getclientID()).equals(rowKey))
            return client;
    }
    return null;
}
@Override
public Object getRowKey(ClientBean client) {
    return Integer.toString(client.getclientID());
}
@Override
public List<ClientBean> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {
    List<ClientBean> data = new ArrayList<ClientBean>();
    //filter
    for(ClientBean client : datasource) {
        boolean match = true;
        for(Iterator<String> it = filters.keySet().iterator(); it.hasNext();) {
            try {
                String filterProperty = it.next();
                String filterValue = filters.get(filterProperty);
                String fieldValue = String.valueOf(client.getClass().getField(filterProperty).get(client));
                if(filterValue == null || fieldValue.toLowerCase().startsWith(filterValue.toLowerCase())) {
                    match = true;
                } else {
                    match = false;
                    break;
                }
            } catch(Exception e) {
                match = false;
            }
        }
        if(match) {
            data.add(client);
        }
    }
    //sort
    if(sortField != null) {
        Collections.sort(data, new LazySorter(sortField, sortOrder));
    }
    //rowCount
    int dataSize = data.size();
    this.setRowCount(dataSize);
    //paginate
    if(dataSize > pageSize) {
        try {
            return data.subList(first, first + pageSize);
        }
        catch(IndexOutOfBoundsException e) {
            return data.subList(first, first + (dataSize % pageSize));
        }
    }else {
        return data;
    }
}
}

clientUitility.java (managedbean)

public class ClientUitility {
private LazyDataModel<ClientBean> lazyModel;
private ClientBean client = new ClientBean();
private List<ClientBean> clientAll;// = new ArrayList<ClientBean>();

/** Creates a new instance of ClientUitility */
public ClientUitility() {
    client = new ClientBean();
    clientAll = new ArrayList<ClientBean>();
    //int userID = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString());
    clientAll = ClientService.GenerateClientList(1);
    lazyModel = new LazyClientDataModel(clientAll);
}
// setter and getter of client 
// getter for lazymodel
public void deleteRecord(ActionEvent actionEvent) {
    try {
        System.out.println("Delete record Called....");
        int ClientID = client.getclientID();            
        ClientService.DeleteClient(client);
        client = new ClientBean();
        clientAll = ClientService.GenerateClientList(1);
        lazyModel = new LazyClientDataModel(clientAll);
        FacesMessage msg = new FacesMessage("Client Deleted", "");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
public void save(ActionEvent actionEvent) {
    System.out.println("Save record Called....");
    ClientService.AddClient(client);
    client = new ClientBean();
    clientAll = ClientService.GenerateClientList(1);
    lazyModel = new LazyClientDataModel(clientAll);
    FacesMessage msg = new FacesMessage("Client Created", "");
    FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:28:22+00:00Added an answer on June 6, 2026 at 12:28 am

    I have changed PF 3.2 instead of PF 3.3 and it’s work smoothly.
    Check this link: http://forum.primefaces.org/viewtopic.php?f=3&t=22216.
    Its bug in PF3.3. No need to change any thing in my project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JSF templates and Primefaces. Javascript code does not seem to be working
I am working with MyFaces/Primefaces and I have a problem to get information using
Working with JSF 2.0 (and Primefaces), is there a way to fire an ActionListener
I am trying to implement jQuery with PrimeFaces and JSF components, but it's not
I'm working with Primefaces.My functionality is to display the records in a datatable with
I'm working on a JSF 2.0 project using Mojarra, PrimeFaces and Tomcat 6.x, but
I'm working with JSF and PrimeFaces and I am using Facelets as view technology.
I'm using JSF 2.0 and primefaces. I have one page with several inputs inside
I am working on a simple messenger using JSF and PrimeFaces. I would like
Working with C and Win32, I have a problem where my program freezes instead

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.