Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8629501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:49:25+00:00 2026-06-12T08:49:25+00:00

I have a question on pagination module in Play Framework ( ver 1.x), i

  • 0

I have a question on pagination module in Play Framework ( ver 1.x),
i have setup pagination to only show one object per page, and some other customized settings,
in the controller:

import java.util.ArrayList;
import java.util.List;

import play.modules.paginate.ValuePaginator;
import play.mvc.Controller;

public class Application extends Controller {

public static void index() {

    List<String> strings = new ArrayList<String>();
    strings.add("Kalle");
    strings.add("Karin");
    strings.add("Dixie");
    strings.add("Edvin");
    strings.add("Gustav");
    strings.add("Axel");

    int pos = 0;

    for(String str : strings){
        if(str.equals("Axel")){
            pos += strings.indexOf(str);
            break;
        }
    }

    ValuePaginator namePaginator = new ValuePaginator(strings);
    namePaginator.setPageSize(1);
    namePaginator.setBoundaryControlsEnabled(false);
    namePaginator.setPagesDisplayed(0);

    renderArgs.put("pos", pos);
    renderArgs.put("namePaginator", namePaginator);
    render();
}

And in the template:

#{extends 'main.html' /}
#{set title:'Home' /}

*{#{welcome /}}*
${pos}
#{paginate.controls items:namePaginator /}

#{paginate.list items:namePaginator, as:'name'}
${name}
#{/paginate.list}

*{#{list items:strings[pos], as:'string'}
${string}
#{/list}}*  

Now, as you might see in the last part of the template, there is a commented part, using the usual groovy list tag, and since it has an actual list i can force the list to start at a given position “pos”, this is however not possible in the case of using the pagination.
In the case of the “items:namePaginator” it is merely a name placeholder for the underlying list and not really iterable, is there possibly a way of making the pagination start at a specified position within the wrapped list?

Thanks a lot !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:49:26+00:00Added an answer on June 12, 2026 at 8:49 am

    I managed to solve the problem using JQuery instead of using Play Frameworks pagination module for this special case of pagination.

    Principle goes like this, in the controllers action a normal Java ArrayList consisting of objects to my liking, this ArrayList is then converted to a jsonObject using the included Gson library (in Play Framework).

    Gson gson = new Gson();
    String jsonObj = gson.toJson(objects);
    

    By using

    renderArgs.put("jsonObj", jsonObj);
    

    in the controller action to pass the json to the template, by the way my reason for doing all this in the first place was to be able to start “paginating” thru the objects clientside from any position in the list of objects, and to a hidden div in the template.

    Next on i use JQuery to pick up the list,

    $.parseJSON($('#myhiddenlist'));
    

    And then again using JQuery to step back and forth (catching click events on anchor tags for prev and next) thru the list, and displaying the respective object per page.
    Another upside of using JQuery (or javascript for that matter), is that i don’t have to worry about page reload, as is the case with Play Frameworks pagination module.

    JQuery-part

        $(function(){
        var ourlist = $('#ourlist').text();
        var jsonOur = $.parseJSON(ourlist);
        var length = jsonOur.length; 
        var pos = parseInt($('#ourpos').text());
        var showList = $('#showlist');
    
    
        showList.append(jsonOur[pos].name);
        initControls();
    
        function hasPrev(){
            if(pos > 0){
                return true;
            }else{
                return false;   
            }
        }
    
        function hasNext(){
            if(pos < (length - 1)){
                return true;    
            }else{
                return false;
            }
    
        }
    
        function showItem(pos){
            showList.empty();
            showList.append(jsonOur[pos].name);
        }
    
        $('.previous a').click(function(e){
    
            if(hasPrev()){pos--;}
            if(hasPrev()){
                    $('li.next').removeClass('off');
                    $('li.next a').css('color', 'blue');
            }else{
                $('li.previous').addClass('off');
                $('li.previous.off a').css('color', 'grey');
            }
            showItem(pos);
        });
    
        $('.next a').click(function(e){
    
            if(hasNext()){pos++;}
            if(hasNext()){
                $('li.previous').removeClass('off');
                $('li.previous a').css('color', 'blue');
            }else{
                $('li.next').addClass('off');
                $('li.next.off a').css('color', 'grey');
            }
            showItem(pos);
        });
    
        function initControls(){
            if(hasNext()){
                $('li.previous').removeClass('off');
            }else{
                $('li.next').addClass('off');
                $('li.next.off a').css('color', 'grey');
            }
            if(hasPrev()){
                    $('li.next').removeClass('off');
            }else{
                $('li.previous').addClass('off');
                $('li.previous.off a').css('color', 'grey');
            }
        }
    
        //for testing only
        function showPos(pos){
            console.log(pos);
        }
    });
    

    HTML part

    #{extends 'main.html' /}
    #{set title:'Home' /}
    #{content.rightside Pos: pos /}<!-- loads the side content -->
    <div id="ourlist" class="hide">${jsonOurList}</div>
    <div id="ourpos" class="hide">${pos}</div>
    <ul class="pagination">
    <li class="previous"><a href="#">Prev</a></li>
    <li class="next"><a href="#">Next</a></li>
    </ul>
    <div id="showlist"></div>
    

    CSS part

    ul.pagination li {
    display: inline;
    }
    ul.pagination li a {
    outline: none;
    text-decoration: none;
    }
    li.previous.off a,
    li.next.off a {
    color: grey;
    cursor: default;
    }
    li.previous a,
    li.next a {
    color: blue;
    cursor: pointer;
    }
    .hide {
    display: none;
    }
    

    Ok, so this is not really a solution for tweaking the Play module, but a more pragmatic approach, using JQuery.

    Hope this might help anyone having a similar problem.

    //Kalle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have question. I have some app on facebook and getting this error Fatal
I have question concerning a function I created. I would like to show the
I have a pretty simple question, but for some reason I am drawing a
I have a dataTable that uses pagination. Now when my page loads then my
PHP mysql database I have created a follow on question to this one here
I just have one simple question here is the desc: I'm working on news
I am trying to perform some SEO on a pagination control I have on
I have my own hand-rolled PHP MVC framework for some projects that I'm working
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.