multiple paginators using the PaginatorSnippet

33 views
Skip to first unread message

zsuleman

unread,
Jul 21, 2013, 6:21:06 AM7/21/13
to lif...@googlegroups.com
Hi everyone,

I am having issue incorporating two paginators in different tabs on the same page. I have defined two seperate snippets both extending the paginatorsnippet and fetching their respective lists from the db. Everything works fine but somehow the links (next,prev ) donot work correctly. I have overridden the definition of the pageurl function and use the session vars so that the two paginators can maintain their respective current page.

The first tab has the following function overridden in its snippet definition. Both firstNav and secondNav are session vars of type SessionVar[Box[Long]](Empty) each maintaining its own offset

 override def pageUrl(offset: Long): String = {

    var url = appendParams(super.pageUrl(offset),List())
   secondNav.is match{
      case Full(x)=>{
        //set the secondoffset to where ever it was previously if it has stored its current page in its respective session var
          url = appendParams(super.pageUrl(offset), List("secondOffset" ->x.toString()))
          //store your own state in your session var
          firstNav(Full(curPage*itemsPerPage))
      }
      case Empty=>{
       
        firstNav(Full(curPage*itemsPerPage))
      }
    }
  
    url
  }

and the second tab has this function definition in its snippet code


 override def pageUrl(offset: Long): String = {

    var url = appendParams(super.pageUrl(offset),List())
   firstNav.is match{
      case Full(x)=>{
       
          url = appendParams(super.pageUrl(offset), List("firstOffset" ->x.toString()))
          //store your own state in your session var
          secondNav(Full(curPage*itemsPerPage))
      }
      case Empty=>{
       
        secondNav(Full(curPage*itemsPerPage))
      }
    }
  
    url
  }


and i have overwritten the offset params as follows in the two snippets

  override def offsetParam = "firstoffset"
  override def offsetParam = "secondoffset"

This scheme works find except when i chose the first page on the first tab it also sends the offset as "0" to the pageurl function in the second snippet which moves both the paginators to their respective first pages...whereas i was expecting only the first paginator to go to the first page

Can some one help me with this and identify whats the issue with this scheme. Any suggestions on any better approach would be very welcome.

Thanks
Zaineb

Aleph-1

unread,
Jul 21, 2013, 11:32:32 AM7/21/13
to lif...@googlegroups.com
Just out of curiosity; why do you need SessionVars? Your paginator snippet/object could be in a stateful. I guess that would also eliminate your need to have the overridden pageUrl methods thus simplifying the code. 
In the current code; I suspect because the secondPage's offset is not being passed in the queryString when you are navigating between pages on the fist tab; the state for the secondNav is being lost. Make sense?

Best.

zsuleman

unread,
Jul 21, 2013, 3:49:37 PM7/21/13
to lif...@googlegroups.com
I am using sessionvars so that the two snippets (which are stateful) can see each other's current page (maintained in a session var which is visible to both). The reason i want the two snippet to know of the selected page of the other snippet is so that the query string that is generated by the pageurl function can just append that...notice the pageurl function in the first paginator snippet is generating the following string

  url = appendParams(super.pageUrloffset), List("secondOffset" ->x.toString()))

where the "secondOffset" is the offset parameter of the second paginator and it is being set to the value of the selected page of the second paginator that is read from its respective session var...this makes sure that the state is not lost for the second paginator...

I am overriding the pageurl function to make sure that the query string has a correct navigation state for the other paginator while changing its own page

Hope this clears the scenario

Thanks

Aleph-1

unread,
Jul 22, 2013, 2:55:04 AM7/22/13
to lif...@googlegroups.com
Okay. I get that you're using session vars to share state between the two snippets. But given the code you have I am confused. It is not clear which method you have posted goes with which snippet. As in the case below, since you are attempting to carry forward the state of the secondNav; I assume that the method below is from the firstNav snippet; and the second method belongs to the secondNav snippet. 
The code seems to be doing the right thing. A few things though; since you are calling super.pageUrl you don't need to do an appendParams. super.pageUrl will take care of it. Other than that; could perhaps clean it up further to:

override def pageUrl(offset: Long): String = {
    secondNav.is match{
      case Full(x)=>{
        //set the secondoffset to where ever it was previously if it has stored its current page in its respective session var
        appendParams(super.pageUrl(offset), List("secondOffset" ->x.toString()))
   }
      case _ => {    //store your own state in your session var
          firstNav(Full(curPage*itemsPerPage))
     super.pageUrl(offset)
      }
    }
  }

It might also help to see what else is going on. The state is perhaps being thrashed somewhere else in the code?

Regards.

Diego Medina

unread,
Jul 22, 2013, 11:58:40 AM7/22/13
to Lift

The code seems to be doing the right thing. A few things though; since you are calling super.pageUrl you don't need to do an appendParams. super.pageUrl will take care of it. Other than that; could 
perhaps clean it up further to:


or posting a full example following these steps may help too


Thanks

  Diego

 

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
 
---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://fmpwizard.telegr.am

zsuleman

unread,
Jul 22, 2013, 4:25:00 PM7/22/13
to lif...@googlegroups.com
Thanks for your help. I havent used Github before but will try to follow the instructions to upload a running example demonstrating the problem at hand.

regards
Zaineb
Reply all
Reply to author
Forward
0 new messages