[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2007-03-19
3
Medium Priority
?
6,650 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

656 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