[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6725
  • Last Modified:

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.getServerName()+":"+request.getServerPort()+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/main.css">
      
</head>
 
<body>
      <f:view>
            <h:form>
                  <h:dataTable value="#{ChannelFeedsBackingBean.currentRssFeeds}"
                               var="feed"
                                   rowClasses="oddRow, evenRow"
                                   headerClass="tableHeader">
                        <h:column>
                           <f:facet name="header">
                        <h:panelGroup>
                            <h:outputText value="Location"/>
                            <f:verbatim>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</f:verbatim>
                              <h:commandLink styleClass="smallLink"
                                             action="#{ChannelFeedsBackingBean.sortLinkAsc}">
                                  <h:outputText id="ascTitle" value="asc"/>
                                    </h:commandLink>
                              
                              <h:outputText value="," />
                    <!-- Sort decsending -->
                              <h:commandLink       styleClass="smallLink"
                                    action="#{ChannelFeedsBackingBean.sortLinkDec}">
                                               <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="#{ChannelFeedsBackingBean.previous}"
                                 alt="previous"
                                 />
      
                        <h:outputText value="#{ChannelFeedsBackingBean.recordStatus}" />

                             
                        <h:commandButton
                                 value=">"
                                 action="#{ChannelFeedsBackingBean.next}"
                                 alt="next"
                                 />
            
      
       <c:forEach begin="1" end="${ChannelFeedsBackingBean.numberOfPages}" var="i">
               <c:choose>
                     <c:when test="${i!=1}">
                       <h:commandLink styleClass="smallLink"       action="#{ChannelFeedsBackingBean.pageNumber}">
                             <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="#{ChannelFeedsBackingBean.add100Records}"/>
      
                  </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.FacesContext;




/**
 * @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(currentPage),
                        Integer.valueOf(numberOfPages)
                        });
      }

      
      public String rewind () {
            this.rewind(this.rewindFastForwardBy);
            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.rewindFastForwardBy);
            return "fastForward";
      }
 

      public List getCurrentRssFeeds() {
            initCount();
      
            int startRecord = this.currentPage * this.itemsPerPage;
                        switch (this.linkSortOrder) {
                  case SORT_LINK_ASC:
                        return rssDAO.getAllFeedsAsc(startRecord, this.itemsPerPage);
                  case SORT_LINK_DEC:
                        return rssDAO.getAllFeedsDec(startRecord, this.itemsPerPage);
                  case SORT_LINK_NATURAL:
                        return rssDAO.getAllFeeds(startRecord, this.itemsPerPage);
                  default:
                        throw new IllegalStateException("SORT 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;
      }
      
}
0
chaitu chaitu
Asked:
chaitu chaitu
  • 2
1 Solution
 
mnrzCommented:
first, the exception says that you have more than one component with the same ID. check all your code to see if there is mistakenly any ID that is not unique.

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
0
 
mnrzCommented:
after using data scroller in your code in order to treat with your database each time user click on next or previous, you should implement some class
go to this page for more info:

http://wiki.apache.org/myfaces/WorkingWithLargeTables
0
 
chaitu chaituAuthor Commented:
 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().getDataCount(getSomeCriteriaObject());
  List pagedList = getSomeBusinessService().getPagedData(getSomeCriteriaObject(), 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()??

0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now