Introduction
This is another article where the main focus is about how to solve an error message appear. The error message itself appear in a Java web application. Furthermore, the Java web application itself is running using a Primefaces framework. This article is using the setup, setting and also the environment from several previous article exist. The first one is the setting of the Java SDK exist in the article with the title of ‘How to Install JDK Java Development Kit in Microsoft Windows 10’ in this link. As for the project of the Java web application, it refer to another article in this link. That article is an article with the title of ‘How to Create maven-based Web Application in NetBeans IDE’. It contains about how to create the project. For the additional requirement of JSF, just look the article in this link. There is an article with the title of ‘How to Add Primefaces Library to a maven-based Java Web Application in NetBeans IDE’ in that link. Last but not least, the article with the title of ‘How to Add JSF Library to a maven-based Web Application in NetBeans IDE’ in this link.
Solution to solve Error Message
Actually, that JSF file mentioned in the previous part is exist in the Java web application. The error message as exist in the title of this article appear after executing a page in that Java web application. That page is actually rendering a specific JSF file. So, before going on to the solution, for better understanding, the following is the content of that JSF file :
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/html" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"> <head> <title>TODO supply a title</title> <meta name="viewport" content="width-device-width, initial-scale=1.0"> </head> <body> <div>TODO content</div> <div class="card"> <h:form> <h5>Form User with only Basic InputText</h5> <h5>Hello, <p:outputLabel for="username" value="#{basicInputTextView.username}"></p:outputLabel></h5> <p:inputText id="username" value="#{basicInputTextView.username}"/> <p:commandButton update="@form" value="Submit" /> </h:form> </div> <div class="card"> <p:panel header="User List"> <p:dataTable var="user" value="#{userBean.userList}"> <p:column> <f:facet name="header"> <h:outputText value="Username" /> </f:facet> <h:outputText value="#{user.username}" /> </p:column> </p:dataTable> </p> </div> </body> </html>
As for the appearance of the error message itself, it exist as follow :
As for the solution, it is very easy. Just add an attribute in the DataTable component. In term of the attribute, absolutely it is the ‘lazy’ attribute. The reason is because it is actually part of the error message. According to the information in the Primefaces official documentation, the ‘lazy’ attribute is necessary for the DataTable component. The explanation itself exist in this link. In term of lazy attribute for loading data, DataTable has built-in support to deal with huge datasets. But in order to do that, there must be an attribute with the value of ‘true’ to enable lazy loading. As to do that, just revise the script above by adding ‘lazy’ attribute with the value of ‘true’ in the DataTable component as follows :
<p:dataTable var="user" value="#{userBean.userList}" lazy="true"> <p:column> <f:facet name="header"> <h:outputText value="Username" /> </f:facet> <h:outputText value="#{user.username}" /> </p:column> </p:dataTable>
Finally, just try to execute it once more. If there are no more errors, it should display or render the page correctly as follows :