package com.emp.service;
public interface GenericEmplyeeService {
}
------------------------------------------------
package com.emp.service;
import com.emp.dao.respository.DaoRespositoryFactory;
public class GenericService {
protected DaoRespositoryFactory daoFactory;
public GenericService() throws Exception
{
}
public GenericService(DaoRespositoryFactory daoFactory) throws Exception
{
this.daoFactory = daoFactory;
}
}
-----------------------------------
package com.emp.service;
import java.util.List;
import com.emp.dao.respository.DaoRespositoryFactory;
import com.emp.dao.respository.DaoRespositoryTypes;
import com.emp.dao.respository.EmployeeRespository;
import com.emp.dto.EmployeeDto;
import com.emp.entity.Employee;
public class EmplyeeService extends GenericService implements GenericEmplyeeService{
private EmployeeRespository employee;
public EmplyeeService(DaoRespositoryFactory daoFactory) throws Exception
{
super(daoFactory);
this.setEmployee((EmployeeRespository) this.daoFactory.createDaoImpl(DaoRespositoryTypes.EMPLOYEE));
}
public void saveEmlpyee(EmployeeDto employee) throws Exception
{
this.employee.persist(new Employee(employee));
}
public List
findAll() throws Exception {
//List should be fill here
return (List
) this.employee.findAll();
}
public EmployeeRespository getEmployee() {
return employee;
}
public void setEmployee(EmployeeRespository employee) {
this.employee = employee;
}
}
-------------------FACADE --------------------------
package com.emp.sessionfacade.action;
import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
import com.emp.dto.EmployeeDto;
import com.emp.entity.Department;
import com.emp.entity.Employee;
import com.emp.entity.EmployeeManager;
import com.emp.service.EmplyeeService;
import com.opensymphony.xwork2.ActionSupport;
public class EmployeeAction extends ActionSupport
{
private EmplyeeService empService;
@fieldErrors
private String address;
private String empName;
private double salary;
private Department department;
private Set
employeeManagers;
Logger log = Logger.getLogger(EmployeeAction.class);
private static final long serialVersionUID = 1L;
public EmployeeAction(EmplyeeService empService) {
this.empService = empService;
}
public String execute() {
return ActionSupport.SUCCESS;
}
public String save() {
System.out.println("***************");
/*System.out.println(this.getAddress());
System.out.println(this.getEmpName());
System.out.println(this.salary);
//log.info(this.department);
EmployeeDto emp = new EmployeeDto();
emp.setAddress(address);
emp.setEmpName(empName);
emp.setSalary(salary);*/
try {
System.out.println(findAll());
//this.empService.saveEmlpyee(emp);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ActionSupport.SUCCESS;
}
public String remove()
{
return ActionSupport.SUCCESS;
}
public String edit()
{
return ActionSupport.SUCCESS;
}
public String find()
{
return ActionSupport.SUCCESS;
}
public List findAll() throws Exception {
return this.empService.findAll();
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
public Set getEmployeeManagers() {
return employeeManagers;
}
public void setEmployeeManagers(Set employeeManagers) {
this.employeeManagers = employeeManagers;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
public EmplyeeService getEmpService() {
return empService;
}
public void setEmpService(EmplyeeService empService) {
this.empService = empService;
}
}
--------------------------Struts.xml----------
*must declare global error tags
*input type for redirecting when field error occured
views/employee.jsp
login.jsp
----------------------------------------------------------------------------------
===================TAGS====================
%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%
%@taglib uri="/struts-tags" prefix="s" %
======================================
---------------------------------WEB xml---------------------------------------
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
org.springframework.web.context.ContextLoaderListener
------------------Application Context-----------------------------------
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">