0

The problem is that whenever I click the link Next page on Home.xhtml to goto getMoreStatusList Page, the function getMoreStatusList is called non-stop until it throws a index out of bound exception. I am even printing the value of index that I get from the session object statusindex and the string insidegetmorestatusList when inside the getMoreStatusList() method to the console ,I use the method results = results.subList(index,index+5); to create sublist but this line is getting called more than once and is throwing out of bound exception as the value of index gets incremented with each call.

1)Home.xhtml

    <h:head>    
    </h:head>

    <h:body class="thrColElsHdr">        


                <!--  -->
                <div class="items">
                    <div id="scroll_items">
                        <c:forEach var="p" items="#{statusBean.statusList}">
                              //Content

                        </c:forEach>

                    </div>
                </div>

    <a href ="getMoreStatusList.xhtml">Next page</a>
    </h:body>
    </html>

2) Status Bean(this contains the getMoreStatusList function)

 public class StatusBean {




                public List<Status> getStatusList() {
            FacesContext context = FacesContext.getCurrentInstance();
            HttpSession session = (HttpSession) context.getExternalContext()
                    .getSession(true);
            User user = (User) session.getAttribute("userdet");
            Query query = em.createQuery("SELECT s FROM Status s WHERE s.email='"
                    + user.getEmail() + "' ORDER BY s.timeMillis desc",
                    Status.class);
            List<Status> results = query.getResultList();

            Collections.sort(results);
            results = results.subList(0, 5);

            session.setAttribute("statusindex", 5);
            return results;

        }

        public List<Status> getMoreStatusList() {

            System.out.println("Inside getMoreStatusList");
            FacesContext context = FacesContext.getCurrentInstance();
            HttpSession session = (HttpSession) context.getExternalContext()
                    .getSession(false);
            User user = (User) session.getAttribute("userdet");
            Query query = em.createQuery("SELECT s FROM Status s WHERE s.email='"
                    + user.getEmail() + "' ORDER BY s.timeMillis desc",
                    Status.class);
            List<Status> results = query.getResultList();

            Collections.sort(results);
            int index = (int) session.getAttribute("statusindex");
            System.out.println(index);
            results = results.subList(index,index+5);
            session.setAttribute("statusindex", index + 5);
            return results;

        }


    }

3) getMoreStatusList.xhtml

<h:head></h:head>
<h:body>

            <c:forEach var="p" items="#{statusBean.moreStatusList}">

                      // Content
            </c:forEach>


</h:body>

</html>

3) Stacktrace(I have cut it short because the limit is 30000)

Inside getMoreStatusList
[EL Finest]: 2013-03-03 15:09:47.527--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.527--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.527--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [amlan@ymail.com]
[EL Finest]: 2013-03-03 15:09:47.529--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.529--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Friend sql="SELECT FRIENDREQUESTID, EMAIL, FRIENDEMAIL, STATUS FROM FRIEND WHERE (EMAIL = ?)")
[EL Finest]: 2013-03-03 15:09:47.529--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.529--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT FRIENDREQUESTID, EMAIL, FRIENDEMAIL, STATUS FROM FRIEND WHERE (EMAIL = ?)
    bind => [amlan@ymail.com]
[EL Finest]: 2013-03-03 15:09:47.53--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.53--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.53--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.53--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [ramanujonlyme@gmail.com]
[EL Finest]: 2013-03-03 15:09:47.531--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.531--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.531--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.531--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [atinr4@gmail.com]
[EL Finest]: 2013-03-03 15:09:47.531--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
5
Inside getMoreStatusList
[EL Finest]: 2013-03-03 15:09:47.532--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.532--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.532--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [amlan@ymail.com]
[EL Finest]: 2013-03-03 15:09:47.533--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.533--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Friend sql="SELECT FRIENDREQUESTID, EMAIL, FRIENDEMAIL, STATUS FROM FRIEND WHERE (EMAIL = ?)")
[EL Finest]: 2013-03-03 15:09:47.534--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.534--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT FRIENDREQUESTID, EMAIL, FRIENDEMAIL, STATUS FROM FRIEND WHERE (EMAIL = ?)
    bind => [amlan@ymail.com]
[EL Finest]: 2013-03-03 15:09:47.534--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.534--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.534--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.535--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [ramanujonlyme@gmail.com]
[EL Finest]: 2013-03-03 15:09:47.535--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.535--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.535--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.535--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [atinr4@gmail.com]
[EL Finest]: 2013-03-03 15:09:47.536--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
10
Inside getMoreStatusList
[EL Finest]: 2013-03-03 15:09:47.537--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.537--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.537--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [amlan@ymail.com]
[EL Finest]: 2013-03-03 15:09:47.538--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.539--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Friend sql="SELECT FRIENDREQUESTID, EMAIL, FRIENDEMAIL, STATUS FROM FRIEND WHERE (EMAIL = ?)")
[EL Finest]: 2013-03-03 15:09:47.539--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.539--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT FRIENDREQUESTID, EMAIL, FRIENDEMAIL, STATUS FROM FRIEND WHERE (EMAIL = ?)
    bind => [amlan@ymail.com]
[EL Finest]: 2013-03-03 15:09:47.539--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.539--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.539--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.54--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [ramanujonlyme@gmail.com]
[EL Finest]: 2013-03-03 15:09:47.54--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.54--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.54--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.54--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [atinr4@gmail.com]
[EL Finest]: 2013-03-03 15:09:47.541--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
15
[EL Finest]: 2013-03-03 15:09:47.541--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Comment sql="SELECT COMMENTID, COMMENT, COMMENTBY, EMAIL, PICTURE, STATUSID, TIMEMILLIS FROM COMMENT WHERE (STATUSID = ?)")
[EL Finest]: 2013-03-03 15:09:47.541--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.541--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT COMMENTID, COMMENT, COMMENTBY, EMAIL, PICTURE, STATUSID, TIMEMILLIS FROM COMMENT WHERE (STATUSID = ?)
    bind => [61]
[EL Finest]: 2013-03-03 15:09:47.542--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
Inside getMoreStatusList
[EL Finest]: 2013-03-03 15:09:47.543--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.543--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.543--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [amlan@ymail.com]
[EL Finest]: 2013-03-03 15:09:47.544--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.545--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Friend sql="SELECT FRIENDREQUESTID, EMAIL, FRIENDEMAIL, STATUS FROM FRIEND WHERE (EMAIL = ?)")
[EL Finest]: 2013-03-03 15:09:47.545--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.545--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT FRIENDREQUESTID, EMAIL, FRIENDEMAIL, STATUS FROM FRIEND WHERE (EMAIL = ?)
    bind => [amlan@ymail.com]
[EL Finest]: 2013-03-03 15:09:47.546--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.546--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.546--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.546--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [ramanujonlyme@gmail.com]
[EL Finest]: 2013-03-03 15:09:47.547--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.547--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.547--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.547--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [atinr4@gmail.com]
[EL Finest]: 2013-03-03 15:09:47.548--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
20
Inside getMoreStatusList
[EL Finest]: 2013-03-03 15:09:47.548--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.548--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.548--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [amlan@ymail.com]
[EL Finest]: 2013-03-03 15:09:47.549--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.549--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Friend sql="SELECT FRIENDREQUESTID, EMAIL, FRIENDEMAIL, STATUS FROM FRIEND WHERE (EMAIL = ?)")
[EL Finest]: 2013-03-03 15:09:47.549--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.55--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT FRIENDREQUESTID, EMAIL, FRIENDEMAIL, STATUS FROM FRIEND WHERE (EMAIL = ?)
    bind => [amlan@ymail.com]
[EL Finest]: 2013-03-03 15:09:47.55--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.55--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.55--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.55--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [ramanujonlyme@gmail.com]
[EL Finest]: 2013-03-03 15:09:47.551--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.551--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.551--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.551--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [atinr4@gmail.com]
[EL Finest]: 2013-03-03 15:09:47.552--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
25
Inside getMoreStatusList
[EL Finest]: 2013-03-03 15:09:47.553--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.553--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.553--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [amlan@ymail.com]
[EL Finest]: 2013-03-03 15:09:47.554--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.554--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Friend sql="SELECT FRIENDREQUESTID, EMAIL, FRIENDEMAIL, STATUS FROM FRIEND WHERE (EMAIL = ?)")
[EL Finest]: 2013-03-03 15:09:47.554--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.554--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT FRIENDREQUESTID, EMAIL, FRIENDEMAIL, STATUS FROM FRIEND WHERE (EMAIL = ?)
    bind => [amlan@ymail.com]
[EL Finest]: 2013-03-03 15:09:47.555--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.555--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.555--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.555--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [ramanujonlyme@gmail.com]
[EL Finest]: 2013-03-03 15:09:47.556--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
[EL Finest]: 2013-03-03 15:09:47.556--UnitOfWork(1909765639)--Thread(Thread[http-bio-8080-exec-1,5,main])--Execute query ReadAllQuery(referenceClass=Status sql="SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC")
[EL Finest]: 2013-03-03 15:09:47.556--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-03 15:09:47.556--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--SELECT STATUSID, EMAIL, PICSTATUS, PICSTATUSDESC, PICTURE, STATUSBY, STATUSMSG, TIMEMILLIS, VIDEOSTATUS, VIDEOSTATUSDESC FROM STATUS WHERE (EMAIL = ?) ORDER BY TIMEMILLIS DESC
    bind => [atinr4@gmail.com]
[EL Finest]: 2013-03-03 15:09:47.557--ServerSession(1973858306)--Connection(1390011245)--Thread(Thread[http-bio-8080-exec-1,5,main])--Connection released to connection pool [default].
30
Mar 03, 2013 3:09:47 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/FreeBird_v.6] threw exception [/getMoreStatusList.xhtml @17,41 test="${p.statusmsg!=null}" /getMoreStatusList.xhtml @17,41 test="${p.statusmsg!=null}": /getMoreStatusList.xhtml @14,60 items="#{statusBean.moreStatusList}": Error reading 'moreStatusList' on type com.bean.StatusBean] with root cause
java.lang.IndexOutOfBoundsException: toIndex = 35
    at java.util.SubList.<init>(AbstractList.java:622)
    at java.util.RandomAccessSubList.<init>(AbstractList.java:775)
    at java.util.AbstractList.subList(AbstractList.java:484)
    at java.util.Vector.subList(Vector.java:1034)
    at com.bean.StatusBean.getMoreStatusList(StatusBean.java:191)
    at sun.reflect.GeneratedMethodAccessor92.invoke(Unknown Source)
    at ......
Wizard Sultan
  • 830
  • 7
  • 22
  • 45
  • i doubt the number of records in the tabke `Staus` is always a multiple of five. so what happens when you have let's 17 records ? you'll get 3 times 5 at the 4th attempt only 2 remind so `results.subList(index,index+5)` will throw an `IndexOutOfBoundsException` . you have to check whether `index+5` exceeds the size of the list, if yes pass `results.size()` instead – A4L Mar 03 '13 at 10:05
  • Ya you are right,I will add an If statement to overcome that problem but still don't get it why the method getMoreStatusList() is getting called more than once when I am just clicking the link to getMoreStatusList page which is supposed to fire the getMoreSatusList() function once on Home.xhtml page – Wizard Sultan Mar 03 '13 at 10:13
  • see: http://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times – Johny T Koshy Mar 03 '13 at 12:30
  • So this is the root of all your questions... – Luiggi Mendoza Mar 04 '13 at 04:14

1 Answers1

1

You should use <ui:repeat> (with xmlns:ui="http://java.sun.com/jsf/facelets") instead of <c:forEach>

foEach is a tag handler, repeat is a component. You can read more about the difference between the two on this blog

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
</h:head>
<h:body class="thrColElsHdr">
    <ui:repeat var="p" value="#{statusBean.statusList}">
        <div>
            <h:outputText label="Status" value="#{p.value}" />
        </div>
    </ui:repeat>
    <a href="getMoreStatusList.xhtml">Next page</a>
</h:body>
</html>

and

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head></h:head>
<h:body>
    <ui:repeat var="p" value="#{statusBean.moreStatusList}">
        <div>
            <h:outputText label="Status" value="#{p.value}" />
        </div>
    </ui:repeat>
    <a href="getMoreStatusList.xhtml">Next page</a>
</h:body>
</html>

to get rid of IndexOutOfBoudsException use the following in getMoreStatusList:

int index = (Integer) session.getAttribute("statusindex");
int end = index+5 > results.size() ? results.size() : index+5;
List<Status> subList = results.subList(index,end);
session.setAttribute("statusindex", end);

and in getStatusList:

int index = 0;
int end = index+5 > results.size() ? results.size() : index+5;
List<Status> subList = results.subList(0, end);
Roger Keays
  • 3,117
  • 1
  • 31
  • 23
A4L
  • 17,353
  • 6
  • 49
  • 70
  • I understand everything what you have written, the thing that I don't understand is that why the getMoreStatusList() is called more than once since I am clicking on the link once only. – Wizard Sultan Mar 03 '13 at 12:24
  • the link is fired only once, the calls to the bean method happens multiple time on the server. read the `Unrelated` part of this answer http://stackoverflow.com/questions/8903483/cforeach-returns-only-one-empty-value – A4L Mar 03 '13 at 12:29
  • `int index = (Integer) session.getAttribute("statusindex"); int end = index+5 > results.size() ? results.size() : index+5; System.out.println("Value of index and end in getMoreStatusList "+index+" "+end); List subList = results.subList(index,end); session.setAttribute("statusindex", end);` I added an extra line to code you suggested,the value of index and end is always 20 and 20 – Wizard Sultan Mar 03 '13 at 12:39
  • when you have navigated to end of your list `end` and `index` will both have the same value witch is equal to the size of the list. you may want to display `Next page` only if there are more elements left. for this you can use `Next page` . you need to provide an implementation for `moreElemens` in your bean witch will basically return `index < subList.size()` – A4L Mar 03 '13 at 12:45
  • I have added as you suggested to the getMoreStatusList.xhtml. After I click the link I am getting a blank page. I observerd the html source code and saw that all input fields are hidden. – Wizard Sultan Mar 03 '13 at 12:54
  • What is the replacement for `` in JSF – Wizard Sultan Mar 03 '13 at 13:05
  • what inputs ? i don't see any in your code, only `// content` – A4L Mar 03 '13 at 13:14
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/25463/discussion-between-amlan-karmakar-and-a4l) – Wizard Sultan Mar 03 '13 at 13:17
  • it is discouraged to use tag handlers in JSF, `c:if` is a tag handler. use JSF components. If you want to conditionally render some html elements then use `` or `` – A4L Mar 03 '13 at 13:19
  • I had to change by because when I was submitting comment or status update it was giving me an exception. Now everything is running fine but problem is that when I am clicking on the next link the page getMoreStatusList.xhtml is firing getMoreStatusList() function multiple times so the all calculation is going wrong – Wizard Sultan Mar 04 '13 at 08:22