Java Reference
In-Depth Information
Implementing the Controller
At this point, we have the presentation layer (View) of our application ready, as
well as the data access layer (Model), the only thing missing is to add a controller
to complete the third layer of our application, which will follow the MVC
design pattern.
package com.ensode.jpaweb;
public class Controller {
private CustomerDAO customerDAO;
private Customer customer;
public CustomerDAO getCustomerDAO() {
return customerDAO;
}
public void setCustomerDAO(CustomerDAO customerDAO) {
this.customerDAO = customerDAO;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public String saveCustomer() {
String returnVal;
try {
customerDAO.persist(customer);
returnVal = "success";
} catch (Exception e) {
returnVal = "failure";
e.printStackTrace();
}
System.out.println(this.getClass().getName() +
".saveCustomer()\nreturnVal = " + returnVal);
return returnVal;
}
}
 
Search WWH ::




Custom Search