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 6992393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:37:43+00:00 2026-05-27T19:37:43+00:00

I have some problems with refreshing on a lazy loaded dataTable of Primesfaces. I’m

  • 0

I have some problems with refreshing on a lazy loaded dataTable of Primesfaces. I’m using 3.0.M4.

Have three classes like in your example with the filter. Tried also the example with lazy loading only but then the data wasn’t reloaded in the controller. So I’ve used the second example with filtering. There I get reload events in the controller (logger displays “Loading data”).
But the table doesn’t show the new data :-(. Why?

Anybody who can help here?

Kind regards!

LazyCarDataModel

package org.jboss.as.quickstarts.helloworld;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;

/**
 * Dummy implementation of LazyDataModel that uses a list to mimic a real datasource like a database.
 */
public class LazyCarDataModel extends LazyDataModel<Car> {

    private static final long serialVersionUID = 1L;

    private List<Car> datasource;

    public LazyCarDataModel(List<Car> datasource) {
        this.datasource = datasource;
    }

    @Override
    public Car getRowData(String rowKey) {
        for(Car car : datasource) {
            if(car.getModel().equals(rowKey))
                return car;
        }

        return null;
    }

    @Override
    public Object getRowKey(Car car) {
        return car.getModel();
    }

    @Override
    public List<Car> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {
        List<Car> data = new ArrayList<Car>();

        //filter
        for(Car car : 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(car.getClass().getField(filterProperty).get(car));

                    if(filterValue == null || fieldValue.startsWith(filterValue)) {
                        match = true;
                    }
                    else {
                        match = false;
                        break;
                    }
                } catch(Exception e) {
                    match = false;
                } 
            }

            if(match) {
                data.add(car);
            }
        }

        //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;
        }
    }
}

LazyTableBean

package org.jboss.as.quickstarts.helloworld;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

import org.primefaces.model.LazyDataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Named
@SessionScoped
public class LazyTableBean implements Serializable {
    private static final long serialVersionUID = 1L;

    private final static Logger logger = LoggerFactory.getLogger(LazyTableBean.class);

    private final static String[] colors;

    private final static String[] manufacturers;

    private List<Car> cars;

    static {
            colors = new String[10];
            colors[0] = "Black";
            colors[1] = "White";
            colors[2] = "Green";
            colors[3] = "Red";
            colors[4] = "Blue";
            colors[5] = "Orange";
            colors[6] = "Silver";
            colors[7] = "Yellow";
            colors[8] = "Brown";
            colors[9] = "Maroon";

            manufacturers = new String[10];
            manufacturers[0] = "Mercedes";
            manufacturers[1] = "BMW";
            manufacturers[2] = "Volvo";
            manufacturers[3] = "Audi";
            manufacturers[4] = "Renault";
            manufacturers[5] = "Opel";
            manufacturers[6] = "Volkswagen";
            manufacturers[7] = "Chrysler";
            manufacturers[8] = "Ferrari";
            manufacturers[9] = "Ford";
    }

    private LazyCarDataModel lazyModel;

    private Car selectedCar;

    public LazyTableBean() {
        cars = new ArrayList<Car>();

        populateLazyRandomCars(cars, 100000);  
        lazyModel = new LazyCarDataModel(cars);  

    }

    public Car getSelectedCar() {
        return selectedCar;
    }

    public void setSelectedCar(Car selectedCar) {
        this.selectedCar = selectedCar;
    }

    public LazyDataModel<Car> getLazyModel() {
        return lazyModel;
    }

    private void populateLazyRandomCars(List<Car> list, int size) {
        System.out.println("Loading data");
        for(int i = 0 ; i < size ; i++) {
            list.add(new Car(getRandomModel(), getRandomYear(), getRandomManufacturer(), getRandomColor()));
        }
    }

    private String getRandomColor() {
        return colors[(int) (Math.random() * 10)];
    }

    private String getRandomManufacturer() {
        return manufacturers[(int) (Math.random() * 10)];
    }

    private int getRandomYear() {
        return (int) (Math.random() * 50 + 1960);
    }

    private String getRandomModel() {
        return UUID.randomUUID().toString().substring(0, 8);
    }

}

And here the xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui" template="template-default.xhtml">

  <ui:define name="content">

    <h:form>

      <p:dataTable var="car" value="#{lazyTableBean.lazyModel}"
        paginator="true" rows="10" lazy="true"
        paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
        rowsPerPageTemplate="5,10,15"
        selection="#{lazyTableBean.selectedCar}" selectionMode="single">
        <p:ajax event="rowSelect"
          listener="#{lazyTableBean.onRowSelect}" update=":form:display"
          oncomplete="carDialog.show()" />

        <p:column headerText="Model">
          <h:outputText value="#{car.model}" />
        </p:column>

        <p:column headerText="Year">
          <h:outputText value="#{car.year}" />
        </p:column>

        <p:column headerText="Manufacturer">
          <h:outputText value="#{car.manufacturer}" />
        </p:column>

        <p:column headerText="Color">
          <h:outputText value="#{car.color}" />
        </p:column>
      </p:dataTable>

      <p:dialog header="Car Detail" widgetVar="carDialog"
        resizable="false" width="200" showEffect="explode"
        hideEffect="explode">

        <h:panelGrid id="display" columns="2" cellpadding="4">

          <f:facet name="header">
            <p:graphicImage
              value="/images/cars/#{lazyTableBean.selectedCar.manufacturer}.jpg" />
          </f:facet>

          <h:outputText value="Model:" />
          <h:outputText value="#{lazyTableBean.selectedCar.model}" />

          <h:outputText value="Year:" />
          <h:outputText value="#{lazyTableBean.selectedCar.year}" />

          <h:outputText value="Manufacturer:" />
          <h:outputText
            value="#{lazyTableBean.selectedCar.manufacturer}" />

          <h:outputText value="Color:" />
          <h:outputText value="#{lazyTableBean.selectedCar.color}" />
        </h:panelGrid>
      </p:dialog>
    </h:form>
  </ui:define>
</ui:composition>
  • 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-05-27T19:37:44+00:00Added an answer on May 27, 2026 at 7:37 pm

    Ok. I have it. Thank you for your ideas! This brought me on another idea. Even the exmaples doesn’t have an id attribute on the p:dataTable tag, I set this now and the table works as expected.
    So a

    <p:dataTable id="dataTable" var="car"...
    

    helped ;-).

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

Sidebar

Related Questions

I have some problems sending mails through SMTP using Spring's MailSender interface and the
I have some problems with Miktex installed on Windows Vista Business SP1/32 bit. I
I have some problems on a site with the concurrent access to a list.
I have some problems with OpenCV s cvCanny(...) and the Image data types it
i have some problems with rowspan: var doc1 = new Document(); doc1.SetPageSize(PageSize.A4.Rotate()); string path
I have some problems sending an id though jquery. I have a form select
I am just starting Java RMI and have some problems with when to use
I am very new to C and I have some problems learning about pointers.
I work with my student group on a project : We have some problems
i want to use .animate function but i have some problems i want to

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.