Announcement Announcement Module
Collapse
No announcement yet.
PagedList demo without using session Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PagedList demo without using session

    Hi, I need some helps from you guys and Spring team experts.

    Currently I am doing a serious project. There is one page involves PagedListHolder class and MultiActionCotroller. So this page can display multipage with page number and sort the item easily. Actually I did my project based on the Spring demo -- PagedList (Please see the demo in Spring release 0.9).

    Everything is working fine. Here is part of my MultiActionController code:

    Code:
    public ModelAndView showInventoryMain(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    
    	RefreshablePagedListHolder listHolder =  (RefreshablePagedListHolder) request.getSession(true).getAttribute(INVENTORY_ATTR);
    	if (listHolder == null) {
    			listHolder = new RefreshablePagedListHolder();
    			listHolder.setSourceProvider(new InventoryListProvider());
    			listHolder.setFilter(new InventoryListFilter());
    			request.getSession(true).setAttribute(INVENTORY_ATTR, listHolder);
    		}
    
    		BindException ex = BindUtils.bind(request, listHolder, "inventoryList");
    
    		listHolder.setLocale(RequestContextUtils.getLocale(request));
    
    		boolean forceRefresh = request.getParameter("forceRefresh") != null;
    
    		listHolder.refresh(forceRefresh);
    Because our project strongly discourages the usage of session. So I try to change this by avoid put listHolder into session. What I did was simply commented out:

    RefreshablePagedListHolder listHolder = (RefreshablePagedListHolder) request.getSession(true).getAttribute(INVENTORY_AT TR);

    and

    request.getSession(true).setAttribute(INVENTORY_AT TR, listHolder);

    But it doesn't work 100% right. One big problem is that the page only displays the first page (even you click other page number). There are also other problems.

    My question is:

    If it is possible in Spring to use PagedListHolder without set the instance into session? Can we use request instead? How?

    If you know the Spring PagedList demo in version 0.9, you may understand better what I mean.

    Any advice will be appreciated. Thank you!

  • #2
    Personaly I do not use PagedListHolder as a general solution for every pagination case. Putting pupulated PagedListHolder into the HttpSession has major inconvenients:
    1. It does not scale well especially when you are working with lot of objects / users
    2. You need to retrieve all the objects that match the user query even though he is really interested in a very small subset
    3. If you configure your HttpSession to expire after one hour or two, and the user does not close his session... you will be using a lot of expensive server memory that serve for nothing.

    In reponse to your question: If you do not want to use HttpSession (and I think you should for small data sets) I would prefer to query the datasource for each user request.

    Comment


    • #3
      Thanks for your reply, Omar.

      I agree with your point of view about PagedListHolder. But for fast coding, it is a handy tool. Also it provides sort function which is what we want.

      If you are familiar with PagedListHolder, I would like to ask further that:

      1) if it is possible to only use PagedListHolder without put it in HttpSession?
      2) how does a PagedListHolder interacts with page parameters and InventoryListFilter? I don't see why PagedListHolder has to be in a scope in order to give correct result from user input. Just want to know the process in the spring framework.

      Thanks,

      Comment


      • #4
        I already used PagedListHolder in a Struts/Spring application. I would like to start with this small hint
        PagedListHolder is defined in package org.springframework.beans.support (there is no magic behind it, it is a pure support/utility class)
        1) if it is possible to only use PagedListHolder without put it in HttpSession?
        to make PagedListHolder full functional (isFirstPage(), isLastPage(), resort()...), it must be populated with the queried data from your datasource. Now, if the PagedListHolder is not persisted between two calls (as you are developing a web application), you have to create a new instance and repopulate it again then programatically set the value of page, pageSize, sort...!!!
        2) how does a PagedListHolder interacts with page parameters and InventoryListFilter? I don't see why PagedListHolder has to be in a scope in order to give correct result from user input. Just want to know the process in the spring framework.
        PagedListHolder does not interact with page parameters... as her name states, she is just a holder. To simplify things, think of PagedListHolder as a java.util.List that has pagination capabilities.
        This means that you are responsable of getting user parameters, populating a new PagedListHolder, or extract an existing one from your HttpSession, apply the indeed changes, then redirect your user to the view.

        I think it will help a lot to read the PagedListHolder source and review the countries sample application.
        HTH

        Comment


        • #5
          Hi, Omar. Thanks for the reply.

          I thought about this and went through the code. Now it is much clear to me. I think I got the idea how to do it.

          The disadvantage (maybe it is advantage) is that Framework hides a lot details behind the scene. It sometimes makes it hard to understand or change the funtionality. I think I didn't understand before about the
          Code:
          		BindException ex = BindUtils.bind(request, listHolder, "inventoryList");
          that is why I wonder how the parameters from page passed to PagedListHolder. Thanks again!

          Comment


          • #6
            PagedListHolder Usage

            Hi,

            I have a scenario where i have to paginate the values (struts + spring application), can u please guide me like how to go abt the same?

            Thanks in advance!

            Regards,
            Ashish

            Comment

            Working...
            X