Home Struts Struts Struts2.2.1 Pagination example in Struts 2.2.1

Ask Questions?

View Latest Questions


 
 

Pagination example in Struts 2.2.1
Posted on: January 21, 2011 at 12:00 AM
Advertisement
In this tutorial you will learn how make a many pages of a large information and displaying them in a limit

Pagination example in Struts 2.2.1

Pagination is a way to divide the data/information into many pages and displaying them one by one in sequence and shorted order. It is required when information the pages become so large to display. Therefore you can divide the information into a limited size and display them.

An example of pagination is given below

SampleInterfaceImp.java

<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
<head>
<title>Pagination Example</title>

</head>

<body bgcolor="">
<s:form action="student">

<display:table id="students" name="students" pagesize="2" export="false" requestURI="/student">
<display:column property="studentRoll" title="Roll" paramId="studentRoll" sortable="true"/>
<display:column property="studentName" title="Name" sortable="true"/>
<display:column property="studentCourse" title="Course" sortable="true" />
<display:setProperty name="paging.banner.placement" value="bottom" />
</display:table>

</s:form>
</body>
</html>

StudentBean.java

package net.roseindia;

import java.io.Serializable;

public class StudentBean implements Serializable{
	String studentName;
	String studentRoll;
	String studentCourse;
	
	StudentBean(){
		
	}
	StudentBean(String name, String roll, String course){
		this.studentName=name;
		this.studentRoll=roll;
		this.studentCourse=course;
	}
	public String getStudentName() {
		return studentName;
	}
	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}
	public String getStudentRoll() {
		return studentRoll;
	}
	public void setStudentRoll(String studentRoll) {
		this.studentRoll = studentRoll;
	}
	public String getStudentCourse() {
		return studentCourse;
	}
	public void setStudentCourse(String studentCourse) {
		this.studentCourse = studentCourse;
	}
	
}

StudentAction.java

package net.roseindia;

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

import com.opensymphony.xwork2.ActionSupport;

public class StudentAction extends ActionSupport{
private static final long serialVersionUID = 1L;

private java.util.List<StudentBean> students=null;
private List selectStudent=null;

@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
java.util.List<StudentBean> students=new ArrayList<StudentBean>();
students.add(new StudentBean("John","1","B.Tech"));
students.add(new StudentBean("Jony","2","M.Tech"));
students.add(new StudentBean("Mark Voucher","3","B.Tech"));
students.add(new StudentBean("Sandy","4","B.Tech"));
students.add(new StudentBean("Sancy Decosta","5","MCA"));
students.add(new StudentBean("Rithus Johny","6","M.Tech"));
students.add(new StudentBean("Kotansy","7","MCA"));
students.add(new StudentBean("Rans Conhty","8","B.Tech"));
students.add(new StudentBean("Reithom","9","M.Tech"));
students.add(new StudentBean("Kathy Seri Kotaan","10","B.Tech"));
setStudents(students);
return SUCCESS;
}

public List getSelectStudent() {
return selectStudent;
}

public void setSelectStudent(List selectStudent) {
this.selectStudent = selectStudent;
}

public java.util.List<StudentBean> getStudents() {
return students;
}

public void setStudents(java.util.List<StudentBean> students) {
this.students = students;
}
}

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />

<package name="roseindia" namespace="/" extends="struts-default">

<default-action-ref name="paging" />

<action name="student" class="net.roseindia.StudentAction">
<result name="success">/jsp/displayStudent.jsp</result>
</action>

</package>

</struts>

When you run this application it will display message as shown below:


 
 
 

Download this example code

Related Tags for Pagination example in Struts 2.2.1:


DMCA.com