Discussions

Web tier: servlets, JSP, Web frameworks: How to Displays results as Pages

  1. How to Displays results as Pages (4 messages)

    Hi,
      I am using a servlet that calls a bean which does a backend query and gets some Values as Elements. I am not using JDBC connections but using JCO connections to connect to SAP and get the required table Values. I have stored the table values into an Arraylist as follows in my Servlet

    ComputeSearchBean Search=new ComputeSearchBean();
    ArrayList beans = new ArrayList();
    for(int i=0; i<Project_Prps.getNumRows(); i++){
            Project_Prps.setRow(i);
    int j=0;
    Search.setWBSXYZ(Project_Prps.getString("XYZ"));
    j=j+1;
    Search.setWBSABC(Project_Prps.getString("ABC")); beans.add(Search);
    }

    Then a call the required JSP file in which i should use the table values as

    req.getSession(true).setAttribute("Search1", beans);
    String url = "/Search.jsp"; //relative url for display jsp page
    ServletContext sc = getServletContext();
    RequestDispatcher rd = sc.getRequestDispatcher(url);
    rd.forward(req, resp);

    My question is how to implement the JSP which will have the results diplayed as 50 elements per page. User can then use the next or previous to scroll across the webpage to see more results. How should i take care of the session so that through out the session user will see the results for his queries.
    And i am talking about search results that could be 0 results or 500 results. dynamically how should i write the jsp page so that it displays them in a table in the center of the page.

    Thanks and any help will be greatly appreciated.
    Ravi
  2. ravi,
       There is a J2EE Design Pattern designed for just such a requirement - the value list handler pattern. There are lots of implementations available out there on the web - e.g. http://valuelist.sourceforge.net.

    If you want to go about it yourself, write a ValueListHandler class, an instance of which will be used for a user query. It will act as a container for the data returned from SAP, and will be stored in the Session. It will contain internal member data to keep track of 'where' in the resultset the user is looking.

    As for the table, if you are using Struts/JSTL you can use the iterate tags perhaps? You might actually check out the link I gave above, http://valuelist.sourceforge.net, this uses a custom tag to render HTML tables, so this might meet your needs perfectly.

    Trevor
  3. Take a look at Display Tag @ http://displaytag.sourceforge.net/
  4. Thanks,
      Well my data was small enough that i used ArrayList. The links that you guys have provided was excellent. May be Ill use this in the future when my records are larger.
    Right now I have used a simple ArrayList and kept in a session. Then i parsed through this Arraylist everytime user calls the prev or next button, And some logic to disable to prev and next when the list is at the begining or end of the list.

    But now i am thinking of a performance issue, I have a question....How much memory does it take to save a session object(ArrayList ). What if the number of users are more and accessing the system at the same time is large.

    Can any one throw some light on this issue..

    Thanks again
    Ravi
  5. How to Displays results as Pages[ Go to top ]

    How much memory does it take to save a session object(ArrayList ). What if the number of users are more and accessing the system at the same time is large.
    It takes at least as much memory as your list requires. Obviously, that varies with the size of the objects and the number of objects in a list. If the objects in your list are large, or there are many of them, then that can be a lot. Even if the objects in the list aren't that big, you're correct about the need to consider the number of users that might have lists in memory at any one time.

    You might consider using something like JMeter to stress-test your implementation.