Javabean:visit class
public class Visit implements Serializable {
//... Other properties
//private Long visit_cust_id;//Client ID
private customer customer;
Private Long visit_user_id;//owner ID
private user user;
}
Customer class
public class Customer implements Serializable {
//... Other attributes
private String cust_name;//' Customer name (company name) '
}
Front:
<input type= "text" name= "Customer.cust_name"/>
Purpose
Encapsulate text box data from the front end to the action class in the Customer object
public class Visitaction extends Baseaction implements modeldriven<visit> {
private Visit visit=new (); c2/> @Override public
Visit Getmodel () {return
Visit;
}
Public String Xxx () {
//print encapsulated data cust_name value
}
}
Because the visit object in the driver model contains the customer object, it is not necessary to provide the customer private property and the set method in the action class to encapsulate the customer.cust_name of the front end, otherwise the customer object will always be null Correct procedure
public class Visitaction extends Baseaction implements modeldriven<visit> {
private Visit visit=new (); c1/> @Override public
Visit Getmodel () {return
Visit;
}
Public String Xxx () {
//print encapsulated data cust_name value
Customer customer=visit.getcustomer;
System.out.println (Customer.getcust_name);
}
Or
public class Visitaction extends Baseaction implements modeldriven<visit> {
private Visit visit=new (); c1/> @Override public
Visit Getmodel () {return
Visit;
}
Private customer customer;
Public String Xxx () {
//print encapsulated data cust_name value
customer=visit.getcustomer;
System.out.println (Customer.getcust_name);
}
Wrong procedure
public class Visitaction extends Baseaction implements modeldriven<visit> {private Visit visit=new ();
@Override public Visit Getmodel () {return Visit;
Private customer customer;
Public Customer GetCustomer () {return customer;
public void Setcustomer (customer customer) {This.customer = customer;
Public String Xxx () {//Print encapsulated data Cust_name value//System.out.println (Customer.getcust_name); Error, NULL pointer exception}}
public class Visitaction extends Baseaction implements modeldriven<visit> {private Visit visit=new ();
@Override public Visit Getmodel () {return Visit;
Private Customer Customer=visit.getcustomer;
Public String Xxx () {//Print encapsulated data Cust_name value//System.out.println (Customer.getcust_name); Error, NULL pointer exception}}