Problem: I want to use primefaces lazy loading data table . When I used ,
LazyDataModel overrride load metod never executed in a my constructor. So that I can not call portalAccessLogDAO.getUsageList(userName, from,pageRequest); metod. We used primafaces in this project everything is fine .But at lazy loading data table bellow code does not work! Any suggession?Please Help .Thanks
BACKING BEAN
public class DailyStatistics extends AbstractBackingBean {
private static final long serialVersionUID = -2861479855082422223L;
@Autowired
private PortalAccessLogDAO portalAccessLogDAO;
private static final Logger logger = Logger.getLogger(DailyStatistics.class);
private Date from;
private String userName = null;
private boolean flag;
private List<PortalAccessLog> lazyPortalAccessLog=null;
private List<PortalAccessLog> actualList = new ArrayList<PortalAccessLog>();
private LazyDataModel<PortalAccessLog> lazyModel;
public DailyStatistics() {
System.out.println("constructor");
lazyModel = new LazyDataModel<PortalAccessLog>() {
private static final long serialVersionUID = 1L;
/**
* Dummy implementation of loading a certain segment of data.
* In a real application, this method should load data from a datasource
*/
public List<PortalAccessLog> load(int first, int pageSize, String sortField, boolean sortOrder, Map<String,String> filters) {
logger.info( "Loading the lazy car data between {0} and {1}" +new Object[]{first, (first+pageSize)});
System.out.println("dfdf");
//Sorting and Filtering information are not used for demo purposes just random dummy data is returned
final PageRequest pageRequest = new PageRequest(first, first+pageSize);
List<PortalAccessLog> lazyPortalAccessLog = new ArrayList<PortalAccessLog>();
lazyPortalAccessLog = portalAccessLogDAO.getUsageList(userName, from,pageRequest);
return lazyPortalAccessLog;
}
};
}
public List<PortalAccessLog> searchDaily() {
logger.debug("search daily usage list method..");
System.out.println(userName + "userNameuserName");
lazyModel = new LazyDataModel<PortalAccessLog>() {
private static final long serialVersionUID = 1L;
/**
* Dummy implementation of loading a certain segment of data.
* In a real application, this method should load data from a datasource
*/
@Override
public List<PortalAccessLog> load(int first, int pageSize, String sortField, boolean sortOrder, Map<String,String> filters) {
logger.info( "Loading the lazy car data between {0} and {1}" +new Object[]{first, (first+pageSize)});
System.out.println("dfdf");
//Sorting and Filtering information are not used for demo purposes just random dummy data is returned
final PageRequest pageRequest = new PageRequest(first, first+pageSize);
List<PortalAccessLog> lazyPortalAccessLog = new ArrayList<PortalAccessLog>();
lazyPortalAccessLog = portalAccessLogDAO.getUsageList(userName, from,pageRequest);
return lazyPortalAccessLog;
}
};
/**
* In a real application, this number should be resolved by a projection query
*/
lazyModel.setRowCount(1000);
if (lazyPortalAccessLog!=null && lazyPortalAccessLog.isEmpty()) {
MessageUtil.addI18NMessage(FacesMessage.SEVERITY_INFO,
CrewDutyI18nBundles.MESSAGES.getBundleName(),
"error.nodata");
flag = false;
return null;
}
return lazyPortalAccessLog;
}
public List<PortalAccessLog> getLazyPortalAccessLog() {
return lazyPortalAccessLog;
}
public void setLazyPortalAccessLog(List<PortalAccessLog> lazyPortalAccessLog) {
this.lazyPortalAccessLog = lazyPortalAccessLog;
}
public List<PortalAccessLog> getActualList() {
return actualList;
}
public void setActualList(List<PortalAccessLog> actualList) {
this.actualList = actualList;
}
public LazyDataModel<PortalAccessLog> getLazyModel() {
return lazyModel;
}
public void setLazyModel(LazyDataModel<PortalAccessLog> lazyModel) {
this.lazyModel = lazyModel;
}
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public Date getFrom() {
return from;
}
public void setFrom(Date from) {
this.from = from;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
JSF PAGE
<p:dataTable var="car" value="#{dailyStatisticsBean.lazyModel}"
paginator="true" rows="10" lazy="true"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" >
<f:facet name="header">
#{dailyStatisticsBean.portalList}
</f:facet>
<p:column headerText="#{msg['label.statistics.userName']}">
<h:outputText value="#{data.accessCount}" />
</p:column>
<p:column headerText="#{msg['label.statistics.accessCount']}">
<h:outputText value="#{data.username}" />
</p:column>
</p:dataTable>
LazyDataModel overrride load metod does not execute
I could not used primefaces lazy loading data table . I wrote custome code for pagination. With Spring data jpa pagination is very simple,
just cominicate your view with spring data jpa repository.Pagination support, dynamic query execution, ability to integrate custom data access code
for more information spring data japa
http://www.springsource.org/spring-data/jpa
JSF PAGE
BACKING BEAN
just cominicate your view with spring data jpa repository.Pagination support, dynamic query execution, ability to integrate custom data access code
for more information spring data japa
http://www.springsource.org/spring-data/jpa
JSF PAGE
Code: Select all
<p:panel rendered="#{dailyStatisticsBean.flag}" id="dataPanel">
<p:commandLink value="First" styleClass="blue-button" ajax="true"
update="outRegionPanel"
action="#{dailyStatisticsBean.goToFirstPage}" />
<h:outputText value=" " />
<p:commandLink value="Next" styleClass="blue-button" ajax="true"
update="outRegionPanel"
action="#{dailyStatisticsBean.goToNexPage}" />
<h:outputText value=" " />
<h:selectOneMenu value="#{dailyStatisticsBean.rowIndex}">
<f:selectItems value="#{dailyStatisticsBean.pageRowList}" />
<p:ajax update="dataPanel"
listener="#{dailyStatisticsBean.loadLazyDAO}" />
</h:selectOneMenu>
<h:outputText value=" " />
<p:commandLink value="Previous" styleClass="blue-button"
ajax="true" update="outRegionPanel"
action="#{dailyStatisticsBean.goToPreviousPage}" />
<h:outputText value=" " />
<p:commandLink value="Last" styleClass="blue-button" ajax="true"
update="outRegionPanel"
action="#{dailyStatisticsBean.goToLastPage}" />
<h:outputText value="Page Size:"
style="margin-left:600px;" />
<h:selectOneMenu value="#{dailyStatisticsBean.pageSize}" >
<f:selectItem itemLabel="5" itemValue="5" />
<f:selectItem itemLabel="10" itemValue="10" />
<f:selectItem itemLabel="20" itemValue="20" />
<f:selectItem itemLabel="30" itemValue="30" />
<f:selectItem itemLabel="40" itemValue="40" />
<f:selectItem itemLabel="50" itemValue="50" />
<p:ajax update="dataPanel"
listener="#{dailyStatisticsBean.loadLazyDAOOnChangePageSize}" />
</h:selectOneMenu>
<p:dataTable var="data" rows="#{dailyStatisticsBean.pageSize}"
value="#{dailyStatisticsBean.lazyPortalAccessLog}">
<p:column>
<f:facet name="header">
<h:outputText value="#{msg['label.statistics.userName']}" />
</f:facet>
<h:outputText value="#{data.username}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{msg['label.statistics.accessCount']}" />
</f:facet>
<h:outputText value="#{data.accessCount}" />
</p:column>
</p:dataTable>
</p:panel>
Code: Select all
public class DailyStatistics extends AbstractBackingBean {
private static final long serialVersionUID = -2861479855082422223L;
@Autowired
private PortalAccessLogDAO portalAccessLogDAO;
private static final Logger logger = Logger.getLogger(DailyStatistics.class);
private Date from;
private String userName = null;
private boolean flag;
private List<PortalAccessLog> lazyPortalAccessLog = new ArrayList<PortalAccessLog>();;
private LazyDataModel<PortalAccessLog> lazyModel;
private int totalRowsCount;
private int pageSize = 5;
private int rowIndex = 1;
private int numberOfPages;
private List<SelectItem> pageRowList = new ArrayList<SelectItem>();
public DailyStatistics() {
}
public void loadLazyDAO() {
logger.info("loadLazyDAO Method...");
Page<PortalAccessLog> lazyList = portalAccessLogDAO.getUsageList(userName, from, new PageRequest(rowIndex - 1, pageSize)); // 0// first page
lazyPortalAccessLog = lazyList.getContent();
totalRowsCount = (int) lazyList.getTotalElements();
numberOfPages = lazyList.getTotalPages();
preparePageRowsCombo(numberOfPages);
flag = true;
if (lazyPortalAccessLog == null || lazyPortalAccessLog.isEmpty()) {
MessageUtil.addI18NMessage(FacesMessage.SEVERITY_INFO,
CrewDutyI18nBundles.MESSAGES.getBundleName(),"error.nodata");
flag = false;
}
}
public void loadLazyDAOOnChangePageSize() {
logger.info("loadLazyDAOOnChangePageSize...");
rowIndex=1;
Page<PortalAccessLog> lazyList = portalAccessLogDAO.getUsageList(userName, from, new PageRequest(rowIndex - 1, pageSize)); // 0// first page
lazyPortalAccessLog = lazyList.getContent();
totalRowsCount = (int) lazyList.getTotalElements();
numberOfPages = lazyList.getTotalPages();
preparePageRowsCombo(numberOfPages);
}
public List<PortalAccessLog> getLazyPortalAccessLog() {
return lazyPortalAccessLog;
}
public void setLazyPortalAccessLog(List<PortalAccessLog> lazyPortalAccessLog) {
this.lazyPortalAccessLog = lazyPortalAccessLog;
}
public LazyDataModel<PortalAccessLog> getLazyModel() {
return lazyModel;
}
public void setLazyModel(LazyDataModel<PortalAccessLog> lazyModel) {
this.lazyModel = lazyModel;
}
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public Date getFrom() {
return from;
}
public void setFrom(Date from) {
this.from = from;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getTotalRowsCount() {
return totalRowsCount;
}
public void setTotalRowsCount(int totalRowsCount) {
this.totalRowsCount = totalRowsCount;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getRowIndex() {
logger.info("rowIndex:"+rowIndex);
return rowIndex;
}
public void setRowIndex(int rowIndex) {
this.rowIndex = rowIndex;
}
public int getNumberOfPages() {
return numberOfPages;
}
public void setNumberOfPages(int numberOfPages) {
this.numberOfPages = numberOfPages;
}
public List<SelectItem> getPageRowList() {
return pageRowList;
}
public void setPageRowList(List<SelectItem> pageRowList) {
this.pageRowList = pageRowList;
}
public void goToFirstPage() {
rowIndex = 1;
loadLazyDAO();
}
public void goToLastPage() {
rowIndex = numberOfPages;
loadLazyDAO();
}
public void goToNexPage() {
if (rowIndex < numberOfPages) {
rowIndex = rowIndex + 1;
loadLazyDAO();
}
}
public void goToPreviousPage() {
if (rowIndex > 1) {// 1 is a first page
rowIndex = rowIndex - 1;
loadLazyDAO();
}
}
public void preparePageRowsCombo(int count) {
if (pageRowList != null) {
pageRowList.clear();
}
for (int i = 1; i <= count; i++) {
pageRowList.add(new SelectItem(i, String.valueOf(i)));
}
}
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 30 guests