DZone
Java Zone
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
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > 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 · Java Zone · Interview
Like (0)
Save
Tweet
3.89K 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.

Popular on DZone

  • The Evolution of Configuration Management: IaC vs. GitOps
  • How To Integrate Third-Party Login Systems in Your Web App Using OAuth 2.0
  • 6 Things Startups Can Do to Avoid Tech Debt
  • Stupid Things Orgs Do That Kill Productivity w/ Netflix, FloSports & Refactoring.club

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • 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
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo