chaitu chaitu
asked on
java.lang.IllegalStateException: Duplicate component ID '_id0:pageNumber1' found in view.
I am getting below exception;i want google like paging in my jsf page;when i click on page link it should go to the DB trip;i had mixed JSF and JSTL to get hyper links;it is okay??
Duplicate component ID '_id0:pageNumber1' found in view.
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+ request.ge tServerNam e()+":"+re quest.getS erverPort( )+path+"/" ;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSF 'showRssFeedsTable.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2 ,keyword3" >
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet"
type="text/css"
href="<%=basePath%>css/mai n.css">
</head>
<body>
<f:view>
<h:form>
<h:dataTable value="#{ChannelFeedsBacki ngBean.cur rentRssFee ds}"
var="feed"
rowClasses="oddRow, evenRow"
headerClass="tableHeader">
<h:column>
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Location"/>
<f:verbatim> &n bsp; [</f :verbatim>
<h:commandLink styleClass="smallLink"
action="#{ChannelFeedsBack ingBean.so rtLinkAsc} ">
<h:outputText id="ascTitle" value="asc"/>
</h:commandLink>
<h:outputText value="," />
<!-- Sort decsending -->
<h:commandLink styleClass="smallLink"
action="#{ChannelFeedsBack ingBean.so rtLinkDec} ">
<h:outputText id="decTitle" value="desc"/>
</h:commandLink>
<f:verbatim>]</f:verbatim>
</h:panelGroup>
</f:facet>
<h:outputText value="#{feed.sname}"/>
</h:column>
</h:dataTable>
<h:panelGroup>
<h:commandButton
value=">"
action="#{ChannelFeedsBack ingBean.pr evious}"
alt="previous"
/>
<h:outputText value="#{ChannelFeedsBacki ngBean.rec ordStatus} " />
<h:commandButton
value=">"
action="#{ChannelFeedsBack ingBean.ne xt}"
alt="next"
/>
<c:forEach begin="1" end="${ChannelFeedsBacking Bean.numbe rOfPages}" var="i">
<c:choose>
<c:when test="${i!=1}">
<h:commandLink styleClass="smallLink" action="#{ChannelFeedsBack ingBean.pa geNumber}" >
<h:outputText id="pageNumber" value="#{i}"/>
</h:commandLink>
</c:when>
<c:otherwise>
<c:out value="${i}"/>
</c:otherwise>
</c:choose>
</c:forEach>
</h:panelGroup>
<br />
<!-- <h:panelGroup>
<h:commandButton value="Create Test Data"
action="#{ChannelFeedsBack ingBean.ad d100Record s}"/>
</h:panelGroup>-->
</h:form>
</f:view>
</body>
</html>
Backing bean
******************
package de.laliluna.hibernate;
import java.text.MessageFormat;
import java.util.List;
import java.util.Random;
import javax.faces.context.FacesC ontext;
/**
* @author Rick Hightower, http://www.arc-mind.com Know the Next
*
*/
public final class ChannelFeedsBackingBean {
//private RssFeedDAO rssDAO;
private int currentPage;
private int numberOfPages;
private int pageNumber;
/* This should be parameters or properties stored somewhere */
private final int itemsPerPage = 10;
private final int rewindFastForwardBy = 10;
private static final int SORT_LINK_ASC = 0;
private static final int SORT_LINK_DEC = 1;
private static final int SORT_LINK_NATURAL = 2;
private int linkSortOrder = SORT_LINK_NATURAL;
HibernateRssFeedDAO rssDAO = new HibernateRssFeedDAO();
public ChannelFeedsBackingBean() {
currentPage = 1;
}
public String sortLinkAsc () {
currentPage = 1;
linkSortOrder = SORT_LINK_ASC;
return "sortLinkAsc";
}
public String sortLinkDec () {
currentPage = 1;
linkSortOrder = SORT_LINK_DEC;
return "sortLinkAsc";
}
/*public RssFeedDAO getRssDAO() {
return rssDAO;
}
public void setRssDAO(RssFeedDAO rssDAO) {
this.rssDAO = rssDAO;
}*/
public String getRecordStatus () {
return MessageFormat.format("{1} of {2}",
new Object []{
Integer.valueOf(currentPag e),
Integer.valueOf(numberOfPa ges)
});
}
public String rewind () {
this.rewind(this.rewindFas tForwardBy );
return "rewind";
}
public void rewind (int aRewindFastForwardBy) {
int newPageNumber = currentPage - aRewindFastForwardBy;
if (newPageNumber < 0) {
currentPage = 1;
} else {
currentPage = newPageNumber;
}
}
public void forward (int aRewindFastForwardBy) {
int newPageNumber = currentPage + aRewindFastForwardBy;
if (newPageNumber > this.numberOfPages) {
currentPage = this.numberOfPages;
} else {
currentPage = newPageNumber;
}
}
public String previous () {
this.rewind(1);
return "previous";
}
public String next () {
this.forward(1);
return "next";
}
public String fastForward () {
this.forward(this.rewindFa stForwardB y);
return "fastForward";
}
public List getCurrentRssFeeds() {
initCount();
int startRecord = this.currentPage * this.itemsPerPage;
switch (this.linkSortOrder) {
case SORT_LINK_ASC:
return rssDAO.getAllFeedsAsc(star tRecord, this.itemsPerPage);
case SORT_LINK_DEC:
return rssDAO.getAllFeedsDec(star tRecord, this.itemsPerPage);
case SORT_LINK_NATURAL:
return rssDAO.getAllFeeds(startRe cord, this.itemsPerPage);
default:
throw new IllegalStateException("SOR T ORDER NOT RECOGNIZED!");
}
}
private void initCount() {
numberOfPages = rssDAO.getFeedCount(); // itemsPerPage;
if (currentPage > numberOfPages) {
currentPage=numberOfPages;
}
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getNumberOfPages() {
int i = (numberOfPages/10)+1;
return i;
}
public void setNumberOfPages(int numberOfPages) {
this.numberOfPages = numberOfPages;
}
public int getPageNumber() {
return pageNumber;
}
public void setPageNumber(int pageNumber) {
this.pageNumber = pageNumber;
}
}
Duplicate component ID '_id0:pageNumber1' found in view.
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSF 'showRssFeedsTable.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control"
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet"
type="text/css"
href="<%=basePath%>css/mai
</head>
<body>
<f:view>
<h:form>
<h:dataTable value="#{ChannelFeedsBacki
var="feed"
rowClasses="oddRow, evenRow"
headerClass="tableHeader">
<h:column>
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Location"/>
<f:verbatim> &n
<h:commandLink styleClass="smallLink"
action="#{ChannelFeedsBack
<h:outputText id="ascTitle" value="asc"/>
</h:commandLink>
<h:outputText value="," />
<!-- Sort decsending -->
<h:commandLink styleClass="smallLink"
action="#{ChannelFeedsBack
<h:outputText id="decTitle" value="desc"/>
</h:commandLink>
<f:verbatim>]</f:verbatim>
</h:panelGroup>
</f:facet>
<h:outputText value="#{feed.sname}"/>
</h:column>
</h:dataTable>
<h:panelGroup>
<h:commandButton
value=">"
action="#{ChannelFeedsBack
alt="previous"
/>
<h:outputText value="#{ChannelFeedsBacki
<h:commandButton
value=">"
action="#{ChannelFeedsBack
alt="next"
/>
<c:forEach begin="1" end="${ChannelFeedsBacking
<c:choose>
<c:when test="${i!=1}">
<h:commandLink styleClass="smallLink" action="#{ChannelFeedsBack
<h:outputText id="pageNumber" value="#{i}"/>
</h:commandLink>
</c:when>
<c:otherwise>
<c:out value="${i}"/>
</c:otherwise>
</c:choose>
</c:forEach>
</h:panelGroup>
<br />
<!-- <h:panelGroup>
<h:commandButton value="Create Test Data"
action="#{ChannelFeedsBack
</h:panelGroup>-->
</h:form>
</f:view>
</body>
</html>
Backing bean
******************
package de.laliluna.hibernate;
import java.text.MessageFormat;
import java.util.List;
import java.util.Random;
import javax.faces.context.FacesC
/**
* @author Rick Hightower, http://www.arc-mind.com Know the Next
*
*/
public final class ChannelFeedsBackingBean {
//private RssFeedDAO rssDAO;
private int currentPage;
private int numberOfPages;
private int pageNumber;
/* This should be parameters or properties stored somewhere */
private final int itemsPerPage = 10;
private final int rewindFastForwardBy = 10;
private static final int SORT_LINK_ASC = 0;
private static final int SORT_LINK_DEC = 1;
private static final int SORT_LINK_NATURAL = 2;
private int linkSortOrder = SORT_LINK_NATURAL;
HibernateRssFeedDAO rssDAO = new HibernateRssFeedDAO();
public ChannelFeedsBackingBean() {
currentPage = 1;
}
public String sortLinkAsc () {
currentPage = 1;
linkSortOrder = SORT_LINK_ASC;
return "sortLinkAsc";
}
public String sortLinkDec () {
currentPage = 1;
linkSortOrder = SORT_LINK_DEC;
return "sortLinkAsc";
}
/*public RssFeedDAO getRssDAO() {
return rssDAO;
}
public void setRssDAO(RssFeedDAO rssDAO) {
this.rssDAO = rssDAO;
}*/
public String getRecordStatus () {
return MessageFormat.format("{1} of {2}",
new Object []{
Integer.valueOf(currentPag
Integer.valueOf(numberOfPa
});
}
public String rewind () {
this.rewind(this.rewindFas
return "rewind";
}
public void rewind (int aRewindFastForwardBy) {
int newPageNumber = currentPage - aRewindFastForwardBy;
if (newPageNumber < 0) {
currentPage = 1;
} else {
currentPage = newPageNumber;
}
}
public void forward (int aRewindFastForwardBy) {
int newPageNumber = currentPage + aRewindFastForwardBy;
if (newPageNumber > this.numberOfPages) {
currentPage = this.numberOfPages;
} else {
currentPage = newPageNumber;
}
}
public String previous () {
this.rewind(1);
return "previous";
}
public String next () {
this.forward(1);
return "next";
}
public String fastForward () {
this.forward(this.rewindFa
return "fastForward";
}
public List getCurrentRssFeeds() {
initCount();
int startRecord = this.currentPage * this.itemsPerPage;
switch (this.linkSortOrder) {
case SORT_LINK_ASC:
return rssDAO.getAllFeedsAsc(star
case SORT_LINK_DEC:
return rssDAO.getAllFeedsDec(star
case SORT_LINK_NATURAL:
return rssDAO.getAllFeeds(startRe
default:
throw new IllegalStateException("SOR
}
}
private void initCount() {
numberOfPages = rssDAO.getFeedCount(); // itemsPerPage;
if (currentPage > numberOfPages) {
currentPage=numberOfPages;
}
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getNumberOfPages() {
int i = (numberOfPages/10)+1;
return i;
}
public void setNumberOfPages(int numberOfPages) {
this.numberOfPages = numberOfPages;
}
public int getPageNumber() {
return pageNumber;
}
public void setPageNumber(int pageNumber) {
this.pageNumber = pageNumber;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have some doubts..
http://www.jroller.com/page/cagataycivici?entry=jsf_datatable_with_custom_paging
i am following above link for large Datasets;
public DataModel getMyPagedDataModel() {
int totalListSize = getSomeBusinessService().g etDataCoun t(getSomeC riteriaObj ect());
List pagedList = getSomeBusinessService().g etPagedDat a(getSomeC riteriaObj ect(), getTable1().getFirst(), getTable1().getRows());
PagedDataModel dataModel = new PagedDataModel(pagedList, tatalListSize, getTable1().getRows());
return dataModel;
}
what is getSomeCriteriaObject() here in getMyPagedDataModel()??
first of all where to implement getMyPagedDataModel()(i assume that i should implement in Backing bean )
what is getSomeCriteriaObject() here?
how to this method getTable1().getFirst()??
http://www.jroller.com/page/cagataycivici?entry=jsf_datatable_with_custom_paging
i am following above link for large Datasets;
public DataModel getMyPagedDataModel() {
int totalListSize = getSomeBusinessService().g
List pagedList = getSomeBusinessService().g
PagedDataModel dataModel = new PagedDataModel(pagedList, tatalListSize, getTable1().getRows());
return dataModel;
}
what is getSomeCriteriaObject() here in getMyPagedDataModel()??
first of all where to implement getMyPagedDataModel()(i assume that i should implement in Backing bean )
what is getSomeCriteriaObject() here?
how to this method getTable1().getFirst()??
second, it is better not to use jstl in your codes. you have better use MYfaces components and they have very good pagination component . take a look at following link and find Data Scroller:
http://www.irian.at/myfaces/home.jsf