DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Demystifying SPF Record Limitations
  • How Agile Works at Tesla [Video]
  • Integration Architecture Guiding Principles, A Reference
  • Database Integration Tests With Spring Boot and Testcontainers

Trending

  • Demystifying SPF Record Limitations
  • How Agile Works at Tesla [Video]
  • Integration Architecture Guiding Principles, A Reference
  • Database Integration Tests With Spring Boot and Testcontainers
  1. DZone
  2. Coding
  3. JavaScript
  4. Spring MVC: Sencha Touch List with "Load More" Plugin

Spring MVC: Sencha Touch List with "Load More" Plugin

Tousif  Khan user avatar by
Tousif Khan
·
Feb. 13, 15 · Interview
Like (0)
Save
Tweet
Share
4.12K Views

Join the DZone community and get the full member experience.

Join For Free

in my last post, i demonstrate sencha touch list using spring mvc . the post was good except one thing – we display all movies in a single list at once. for that example its good because we have only 20 movie records to show and sencha touch stores default page size it 25 but consider what will happen if you want to show more records to a list (i.e. list of all countries in world.)

to solve this issue, sencha touch has a paging plug-in ( ext.plugin.listpaging ) that we can use to load a fix records at time. it adds a ‘load more’ button at the bottom of the list. when the user presses this button, the next page of data will be loaded into the store and appended to the list.

continue from our previous post, we just need to modify store, list in javascript file and moviecontroller.java , moviedatabase.java file.

first, add a pagesize config in your movie store.

ext.define('techzoo.store.movie', {
	extend	: 'ext.data.store',
	storeid	: 'moviestore',
    config	: {
    	model	: 'techzoo.model.movie',
    	autoload: true,
    	pagesize: 10,
    	sorters	: 'genre',
    	grouper	: {
    		groupfn	: function(record) {
    			return record.get('genre');
    	    },
    	    sortproperty	: 'genre'
    	},
    	proxy	: {
    		type: 'ajax',
    		url	: 'movies/load.do',
    		reader	: {
    			type	: 'json',
    			totalproperty: 'totalcount',
    			rootproperty: 'movieslist'
    		}
    	}
    }
});
ext.create('techzoo.store.movie');

now edit movielist and add ext.plugin.listpaging class in plugin config.

ext.define('techzoo.view.movielist', {
	extend	: 'ext.dataview.list',
    alias 	: 'widget.movielist',
    config	: {
    	store 	: 'movie',
    	plugins	: [{
            xclass	: 'ext.plugin.listpaging',
            autopaging: true
    	}],
    	grouped	: true,
    	indexbar: true,
    	itemtpl : '{title}',
    	listeners : {
        	itemtap : function(me, index, target, record){
        		ext.msg.alert('movie detail', 
        			'director: ' + record.get('director') + 
        			'<br/>year of release : ' + record.get('yearofrelease'));	
        	}
        },
    	onitemdisclosure : true
    }
});

from backend java side, first we need to modify moviedatabase class method to support paging of list.

package org.techzoo.touch.vo;

import static org.techzoo.touch.vo.movie.moviegenre.action;
import static org.techzoo.touch.vo.movie.moviegenre.comedy;
import static org.techzoo.touch.vo.movie.moviegenre.family;
import static org.techzoo.touch.vo.movie.moviegenre.horror;
import static org.techzoo.touch.vo.movie.moviegenre.war;

import java.util.arraylist;
import java.util.list;

public class moviesdatabase {

	private list<movie> movies = null;
	
	private static moviesdatabase _instance = null;
	
	private moviesdatabase() {
		if(null == movies){
			initializemovies();
		}
	}
	
	public static moviesdatabase getinstance() {
		if(null == _instance){
			return new moviesdatabase();
		}
		return _instance;
	}
	
	public list<movie> getmovies() {
		return movies;
	}
	
	public list<movie> getmoviesbypage(int start, int limit) {
		list<movie> movieslist = movies.sublist(start, start+limit);
		return movieslist;
	}
	
	private void initializemovies() {
		movies = new arraylist<movie>();
		
		/** action **/
		movies.add(new movie(1001, "ek tha tiger", "kabir khan", 2012, action));
		movies.add(new movie(1002, "khiladi", "abbas mastan", 1992, action));
		movies.add(new movie(1003, "kick", "sajid nadiadwala", 2014, action));
		movies.add(new movie(1004, "rowdy rathore", "prabhudheva", 2012, action));
		
		/** horror **/
		movies.add(new movie(1005, "bhoot", "ram gopal varma", 2003, horror));
		movies.add(new movie(1006, "raat", "ram gopal varma", 1992, horror));
		movies.add(new movie(1007, "aatma", "deepak ramsay", 2013, horror));
		movies.add(new movie(1008, "mahal", "kamal amrohi", 1949, horror));
		
		/** comedy **/
		movies.add(new movie(1009, "gol maal", "hrishikesh mukherjee", 1979, comedy));
		movies.add(new movie(1010, "jaane bhi do yaaro", "kundan shah", 1983, comedy));
		movies.add(new movie(1011, "andaz apna apna", "rajkumar santoshi", 1994, comedy));
		movies.add(new movie(1012, "3 idiots", "rajkumar hirani", 2009, comedy));
		
		/** family **/
		movies.add(new movie(1013, "chakde india", "shimit amin", 2007, family));
		movies.add(new movie(1014, "khichdi", "aatish kapadia", 2010, family));
		movies.add(new movie(1015, "vivah", "sooraj barjatya", 2006, family));
		movies.add(new movie(1016, "beta", "indra kumar", 1992, family));
		
		/** war **/
		movies.add(new movie(1017, "border", "jp datta", 1997, war));
		movies.add(new movie(1018, "loc kargil", "jp datta", 2003, war));
		movies.add(new movie(1019, "lakshya", "farhan akhtar", 2004, war));
		movies.add(new movie(1020, "tango cahrlie", "mani shankar", 2005, war));
	}
	
}

and last create a controller method which take ‘start’, and ‘limit’ parameter from request and return a list of movies.

package org.techzoo.touch.controller;

import java.util.hashmap;
import java.util.list;
import java.util.map;

import javax.servlet.http.httpservletrequest;

import org.springframework.stereotype.controller;
import org.springframework.validation.objecterror;
import org.springframework.web.bind.methodargumentnotvalidexception;
import org.springframework.web.bind.servletrequestutils;
import org.springframework.web.bind.annotation.exceptionhandler;
import org.springframework.web.bind.annotation.requestmapping;
import org.springframework.web.bind.annotation.requestmethod;
import org.springframework.web.bind.annotation.responsebody;
import org.techzoo.touch.vo.movie;
import org.techzoo.touch.vo.moviesdatabase;

@controller
@requestmapping("movies")
public class moviecontroller {

	
	@requestmapping(value = "/index")
	public string index()
	{
		return "index";
	}
	
	@requestmapping (value = "/load.do", method = requestmethod.get)
	public @responsebody map<string, object> loadmovies(httpservletrequest request) 
	throws exception
	{
		moviesdatabase mdb = moviesdatabase.getinstance();
		int start = servletrequestutils.getintparameter(request, "start");
		int limit = servletrequestutils.getintparameter(request, "limit");
		list<movie> movies = mdb.getmoviesbypage(start, limit);
		map<string, object> resp = new hashmap<string, object>();
		resp.put("movieslist", movies);
		resp.put("totalcount", mdb.getmovies().size());
		return resp;
	}
	
	
}

output:

when initially list load..

and when after it load all records…

i h0pe you enjoy the post. happy coding…

Sencha Touch

Opinions expressed by DZone contributors are their own.

Trending

  • Demystifying SPF Record Limitations
  • How Agile Works at Tesla [Video]
  • Integration Architecture Guiding Principles, A Reference
  • Database Integration Tests With Spring Boot and Testcontainers

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: