OGNL expression model-driven encapsulation data to obtain NULL __javabean

Source: Internet
Author: User

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}} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.