Home Struts Struts Struts2.2.1 Databaseapps Writing model classes in struts2.2.1

Ask Questions?

View Latest Questions


 
 

Writing model classes in struts2.2.1
Posted on: February 5, 2011 at 12:00 AM
Advertisement
In this section, you will see the how to write a model class in struts application.

Creating model classes

StudentAdmissionModel.java - 

Model class  is a java class(POJO). It has property and method. The method 
name is setter and getter. Which sets and gets value of property.

In our application , It is used for admission process. So it have all the fields  of
admission form as string. The name of string variable must be same as fields name.
There is also to type of met setter and getter which is used for setting and getting
value of string variable. 

StudentAdmissionModel .java

package net.roseindia.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class StudentAdmissionModel implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	private String name="";
	private String fname="";
	private String dob;
	private String class1="";
	private String currentDate="";
	private String address="";
	private String phoneno="";
	private long fee;
	int roll;
	
public int getRoll() {
		return roll;
	}

	public void setRoll(int roll) {
		this.roll = roll;
	}
private List<String> clsseslist;
	
	public StudentAdmissionModel() {
		clsseslist = new ArrayList<String>();
		clsseslist.add("MCA");
		clsseslist.add("MBA");
		clsseslist.add("BCA");
		clsseslist.add("BBA");
		clsseslist.add("PGDCA");
		clsseslist.add("PGDM");
	}

	public List<String> getClsseslist() {
		return clsseslist;
	}
	public void setClsseslist(List<String> clsseslist) {
		this.clsseslist = clsseslist;
	}

	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getFname() {
		return fname;
	}
	public void setFname(String fname) {
		this.fname = fname;
	}
	public String getDob() {
		return dob;
	}
	public void setDob(String dob) {
		this.dob = dob;
	}
	public String getClass1() {
		return class1;
	}
	public void setClass1(String class1) {
		this.class1 = class1;
	}
	public String getCurrentDate() {
		return currentDate;
	}
	public void setCurrentDate(String currentDate) {
		this.currentDate = currentDate;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPhoneno() {
		return phoneno;
	}
	public void setPhoneno(String phoneno) {
		this.phoneno = phoneno;
	}
	public long getFee() {
		return fee;
	}
	public void setFee(long fee) {
		this.fee = fee;
	}
	public String display() {
		System.out.println(getName());
		return "input";
	}
	
}

SearchModel.java

package net.roseindia.model;

public class SearchModel {
	public String s_name;
	private String calss1;
	private String s_roll;
	public String getS_name() {
		return s_name;
	}
	public void setS_name(String sName) {
		s_name = sName;
	}
	public String getCalss1() {
		return calss1;
	}
	public void setCalss1(String calss1) {
		this.calss1 = calss1;
	}
	public String getS_roll() {
		return s_roll;
	}
	public void setS_roll(String sRoll) {
		s_roll = sRoll;
	}
	
	public String display(){
		return "input";
	}
	
}


UpdateModel.java

package net.roseindia.model;

import java.io.Serializable;

public class UpdateModel implements Serializable {

	private static final long serialVersionUID = 1L;
	private String name;
	private String fname;
	private String dob;
	private String class1;
	private String currentDate;
	private String address;
	private String phoneno;
	private long fee;
	int roll;

	public String getName() {
		return name;
	}

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

	public String getFname() {
		return fname;
	}

	public void setFname(String fname) {
		this.fname = fname;
	}

	public String getDob() {
		return dob;
	}

	public void setDob(String dob) {
		this.dob = dob;
	}

	public String getClass1() {
		return class1;
	}

	public void setClass1(String class1) {
		this.class1 = class1;
	}

	public String getCurrentDate() {
		return currentDate;
	}

	public void setCurrentDate(String currentDate) {
		this.currentDate = currentDate;
	}

	public String getAddress() {
		return address;
	}

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

	public String getPhoneno() {
		return phoneno;
	}

	public void setPhoneno(String phoneno) {
		this.phoneno = phoneno;
	}

	public long getFee() {
		return fee;
	}

	public void setFee(long fee) {
		this.fee = fee;
	}

	public int getRoll() {
		return roll;
	}

	public void setRoll(int roll) {
		this.roll = roll;
	}

	public String display() {
		return "input";
	}

}

Related Tags for Writing model classes in struts2.2.1:


DMCA.com