Friday, 25 April 2014

Spring MVC and DisplayTag Example , Pagination

Here I am posting display tag example with Spring. If you need more info about display tag refer this example :-Struts2 pagination using display tag


web.xml



 Spring3Example
 
  dispatcher
  org.springframework.web.servlet.DispatcherServlet
  1
 
 
  dispatcher
  /forms/*
 
 
  index.jsp
 


dispatcher-servlet.xml



 
 

 
 

  
   /WEB-INF/views/
  
  
   .jsp
  
 
 
 
 



index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>




Spring 3, Display tag Examples





bootstrap.min.css
displayTag.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="display" uri="http://displaytag.sf.net/el"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>




Display Tag Pagination Display Tag



 
  
  
  
  
  
  
  
 



user.java

package com.javastoreroom.bean;

public class User {

 private String name;
 private String firstName;
 private String lastName;
 private String nickName;
 private String modernName;
 private String section;
 private String address;

 public User(String names, String first, String last, String nick,
   String modren, String section, String address) {
  this.name = names;
  this.firstName = first;
  this.lastName = last;
  this.nickName = nick;
  this.modernName = modren;
  this.section = section;
  this.address = address;

 }

 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }

 public String getFirstName() {
  return firstName;
 }

 public void setFirstName(String firstName) {
  this.firstName = firstName;
 }

 public String getLastName() {
  return lastName;
 }

 public void setLastName(String lastName) {
  this.lastName = lastName;
 }

 public String getNickName() {
  return nickName;
 }

 public void setNickName(String nickName) {
  this.nickName = nickName;
 }

 public String getModernName() {
  return modernName;
 }

 public void setModernName(String modernName) {
  this.modernName = modernName;
 }

 public String getSection() {
  return section;
 }

 public void setSection(String section) {
  this.section = section;
 }

 public String getAddress() {
  return address;
 }

 public void setAddress(String address) {
  this.address = address;
 }

}

PaginateController

package com.javastoreroom.controllers;

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

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.javastoreroom.bean.User;

@Controller
@RequestMapping("displayTag.html")
public class PaginateController {

 @RequestMapping(method = RequestMethod.GET)
 public String fetchUserList(Model model) {

  List users = new ArrayList<>();

  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "A",
    "Palampur"));
  users.add(new User("Sonu Kumar", "Arun", "Kumar", "Anu", "Aryan", "B",
    "Palampur"));
  users.add(new User("Pawan Kumar", "Arun", "Kumar", "Anu", "Aryan", "C",
    "Palampur"));
  users.add(new User("Satish Kumar", "Arun", "Kumar", "Anu", "Aryan", "D",
    "Palampur"));
  users.add(new User("Arrus Kumar", "Arun", "Kumar", "Anu", "Aryan", "E",
    "Palampur"));
  users.add(new User("Rihan Kumar", "Arun", "Kumar", "Anu", "Aryan", "F",
    "Palampur"));
  users.add(new User("Rishav Kumar", "Arun", "Kumar", "Anu", "Aryan", "G",
    "Palampur"));
  users.add(new User("Test Kumar", "Arun", "Kumar", "Anu", "Aryan", "H",
    "Palampur"));
  users.add(new User("Hello Kumar", "Arun", "Kumar", "Anu", "Aryan", "J",
    "Palampur"));
  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "K",
    "Palampur"));
  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "L",
    "Palampur"));
  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "M",
    "Palampur"));
  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "N",
    "Palampur"));
  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "O",
    "Palampur"));
  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "P",
    "Palampur"));
  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "Q",
    "Palampur"));
  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "R",
    "Palampur"));
  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "S",
    "Palampur"));
  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "T",
    "Palampur"));
  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "Q",
    "Palampur"));
  users.add(new User("Arun Kumar", "Arun", "Kumar", "Anu", "Aryan", "X",
    "Palampur"));
  model.addAttribute("userList", users);
  return "displayTag";

 }

}

Done :) here is out put :-

1 comment:

  1. It's a very nice blog, I really like it.
    Jewellery By Mitali Jain is the best website to buy artificial jewellery online and Jain Jewellery in Jaipur. They sell fancy and attractive products like Earrings for beautiful ears, Rings for fingers, Necklaces for neck, Headgears(maangtikka) for head, Bracelets for wrist, Mask and Glass Chains for Mask and chains, Bookmark Jewellery for book, novel. They also have collections of Vintage Tresor, Summer Luna, Holy Mess, The Mashrab Jaal, Bookmark, and Rakhi Collection. Gift Cards and many more items like this.

    ReplyDelete