Modifying the employeecontroller.java file – HP Integrity NonStop J-Series User Manual

Page 353

Advertising
background image

Modifying the EmployeeController.java File

Modify EmployeeController.java to replace the instance of the EmployeeDao.java class
with the instance of the IEmployeeDao.java interface.

To modify the EmployeeController.java file, complete the following steps:

1.

Change an import statement to import the IEmployeeDao.java interface instead of
EmployeeDao.java

.

import com.hp.empinfo.service.IEmployeeDao;

2.

Replace the EmployeeDao instance with that of IEmployeeDao as:

private IEmployeeDao empdao;
empdao = (IEmployeeDao) wac.getBean("iempdao");

After modification, the EmployeeController.java file must appear as:

package com.hp.empinfo.web;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.hp.empinfo.domain.Employee;
import com.hp.empinfo.service.IEmployeeDao;

public class EmployeeController extends SimpleFormController {

private IEmployeeDao empdao;

public ModelAndView onSubmit(Object command) throws ServletException,
SQLException {

WebApplicationContext wac = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());

empdao = (IEmployeeDao) wac.getBean("iempdao");

int empid = ((Employee) command).getEmpid();
String firstname = ((Employee) command).getFirstname();
String lastname = ((Employee) command).getLastname();
int age = ((Employee) command).getAge();
String email = ((Employee) command).getEmail();
String rord = ((Employee) command).getRord();

if (rord != null && rord.equalsIgnoreCase("Retrieve")) {

Employee emp1 = empdao.getDetail(empid);

Map<String, String> model = new HashMap<String, String>();
model.put("empid", "" + emp1.getEmpid());
model.put("empfn", emp1.getFirstname());
model.put("empln", emp1.getLastname());
model.put("empage", "" + emp1.getAge());
model.put("empemail", emp1.getEmail());

return new ModelAndView("retrieveresult", "model", model);

}

Example of Using Spring Transaction Manager 353

Advertising
This manual is related to the following products: