Solved

java.lang.IllegalStateException: Duplicate component ID '_id0:pageNumber1' found in view.

Posted on 2007-03-19
3
6,561 Views
Last Modified: 2013-11-24
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
Comment
Question by:chaitu chaitu
  • 2
3 Comments
 
LVL 8

Expert Comment

by:mnrz
ID: 18746675
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
 
LVL 8

Accepted Solution

by:
mnrz earned 500 total points
ID: 18746688
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
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 18756009
 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse apache tomcat admin console 52 121
ejb example issues 3 26
pagenation logic how it is working in my code 1 54
Java class and jar 3 24
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question