Now that we’ve created our service facade, it’s time to adapt our web application to use this service facade instead of the dummy objects we used so far. For the Employees, we had a managed bean that contained a list of employees. To get access to our persisted Employee
objects, we have to call the methods in our service facade from the backing bean of our page. We already have the EmployeesTable
backing bean, so let’s add some methods there to access our facade:
private List<Employee> empList; public List<Employee> getEmployees() { if (null == empList) { empList = service.getEmployees(); } return empList; } public void saveSelected(ActionEvent event) { RequestContext rc = RequestContext.getCurrentInstance(); Employee emp = (Employee) rc.getPageFlowScope() .get("selectedEmployee"); service.updateEmployee(emp); }
The getEmployee()
method simply delegates the call to the service. The result is stored in a member variable. Combined with...