dataTable not showing records after loading

UI Components for JSF
Post Reply
nirvanbd
Posts: 45
Joined: 16 Oct 2010, 16:17

05 Nov 2010, 07:49

I have a p:dataTable with LazyDataModel. I am facing two issues with the dataTable.

Firstly, I have forcibly instantiate the LazyTableModel in the constructor of my managedBean otherwise, I get a ClassCastException when primefaces tries to cast ListDataModel to LazyDataModel.

Secondly, when the p:dataTable is populated using the LazyDataModel through my hibernate JPA query, no records are displayed initially. Page links are properly rendered and when I click one of the pageLinks the data shows up nicely. Not only that the firstPage link which initially displayed no data, when clicked again, nicely shows up the data. I don't know why I am getting this behaviour. Here is my code.

xhtml

Code: Select all

                <p:dataTable id="donorTable" value="#{donorSearchBean.donors}" var="donor"
                             paginator="true" rows="10" dynamic="true" lazy="true" 
                             emptyMessage="No Records to Display">
dataModel

Code: Select all

public class DonorLazyDataModel extends LazyDataModel<Donor> {

    public DonorLazyDataModel (QueryName queryName, String firstName, String lastName) {
        super();
        this.setPageSize(10);
        try {
            this.setRowCount((donorSearchService.
                            countDonorsByName(firstName, lastName, queryName)).intValue());
        } catch(Throwable ex) {
            ex.printStackTrace();
        }

    public List<Donor> load(int first, int pageSize, String sortField,
                            boolean sortOrder, Map filters) {
                return  donorSearchService.findDonorsByName(firstName,lastName, queryName, first);
}
regards,
Nirvan

User avatar
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

05 Nov 2010, 13:36

no records are displayed initially
This is a known issue. I already created as issue ticket, but Cagatay closed it as it cannot be replicated.

Link to the related issue ticket:
http://code.google.com/p/primefaces/iss ... il?id=1284


Link to the related forum post:
http://primefaces.prime.com.tr/forum/vi ... 185#p21185
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

nirvanbd
Posts: 45
Joined: 16 Oct 2010, 16:17

05 Nov 2010, 13:51

Miss_Duke,
What should I do now. Am I supposed to comment on the issue ticket link that you posted? Or I have to create another issue ticket. Anyway, is there any temporary solution to this problem ?

regards,
Nirvan.

nirvanbd
Posts: 45
Joined: 16 Oct 2010, 16:17

05 Nov 2010, 20:10

I have posted a comment and provided source files to replicate the issue. Please visit
http://code.google.com/p/primefaces/iss ... il?id=1284 for referring to the issue.

regards,
Nirvan

callahan
Posts: 768
Joined: 27 May 2010, 22:52

05 Nov 2010, 22:11

Nothing is displayed initially because the LazyDataModel called donors is initially empty. Use the example here to get things working: http://www.primefaces.org/showcase/ui/datatableLazy.jsf

nirvanbd
Posts: 45
Joined: 16 Oct 2010, 16:17

06 Nov 2010, 08:08

callahan,
You have misunderstood my issue. The term "initially" meant, after you press the "Fetch Donors" button for the first time, and not when the page is loaded for the first time. I will illustrate the process step by step.

1. Load the dataTableIssue.xhtml in the browser. This is the first time the page is invoked and at this stage the donors lazy model is empty. So the dataTable is shown up correctly with no rows to display.

2. Press the "Fetch Donors" button. This creates a new LazyDataModel and assigns it to donors variable (the LazyDataModel). Now the model has 9 records(or rowCount) and page size is 3. So the first 3 records should be displayed, but the dataTable displays no rows. This is the main issue. To further confirm that model indeed has rows follow the step below.

3. Click on the PageLink numbered 2. Now the next set (4-6) of records suddenly appear and this means that model does has records. And finally press again PageLink numbered 1. The dataTable which was showing no records for the PageLink 1 now shows the first 3 records. We are not changing the wrapped data for the LazyDataModel in this step, then how did the PageLink 1 displayed 3 rows(whereas it displayed none in step 2).

This was the issue that I have logged as comment to an already issued ticket. But there is another issue. If you see the tableBean.java, the method loadDonors() explicitly creates an empty LazyDataModel. If you remove this model creation code, then an ClassCastException is thrown as given below

Code: Select all

javax.faces.model.ListDataModel cannot be cast to org.primefaces.model.LazyDataModel
That is another issue that I wan't to log.

regards,
Nirvan

callahan
Posts: 768
Joined: 27 May 2010, 22:52

06 Nov 2010, 12:28

The DataTable inherits from UIData and UIData caches the DataModel. Currently, the fetchDonors method creates a new LazyDataModel<Donor> and simply assigns it to donors. UIData doesn't know/care about this assignment as it has it's own cached DataModel instance. The managed bean should use one instance of LazyDataModel<Donor> and not several of them.

nirvanbd
Posts: 45
Joined: 16 Oct 2010, 16:17

06 Nov 2010, 13:18

callahan,
Thank you very much for pointing that out. So it turned out to be not an issue but my lack of knowledge of JSF.

regards,
Nirvan

darkBlue
Posts: 27
Joined: 10 Aug 2012, 11:08

26 Aug 2014, 10:52

If the livescroll attribute exists in xhtml dataTable, you can try to remove it. It prevents to load first time.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 27 guests