Making Progress on Assignment 1
JDBC review
A good place to start is the ‘trail’ document on Oracle’s web-site: https://docs.oracle.com/javase/tutorial/jdbc/basics/index.html – main areas of focus: ‘Retrieving and Modifying values from Result Sets’ and ‘Using Prepared Statements’. There are also many examples to be found on the Internet. In many of these examples, there is a fair bit of attention given to cleaning-up the various artifacts: resultSets, connections, statements, etc. Our EmployeeDaoImpl class has an advantage in that we can link the set-up and tear-down of these artifacts to its lifecycle, simplifying the code:
public class EmployeeDaoImpl implements SomeDao, Serializable { /** explicit set serialVersionUID */
private static final long serialVersionUID = 1L;
…
protected void buildConnectionAndStatements() { …
}
@PreDestroy
protected void closeConnectionAndStatements() { …
}
@PostConstruct
Managed Beans
If you take the 20WAssignment1_starter project and deploy it to Payara without making any changes, it will not work. This is because we have not yet made two of our components into ManagedBeans:
@???
@???
public class EmployeeController implements Serializable {
/** explicit set serialVersionUID */
private static final long serialVersionUID = 1L; …
@???
@???
public class EmployeeDaoImpl implements EmployeeDao, Serializable {
/** explicit set serialVersionUID */
private static final long serialVersionUID = 1L; …
Based on the walk-thru screencast video I posted for the Regional Inventory JSF application, you should be able to figure out how to make these classes into Managed Beans and what scope they should have.
XHTML View Component
In the starter project, there is the view component “list-employees.xhtml”. We need to communicate with the controller to load the collection of DTO’s from the database.
Again, based on the walk-thru screecast video I posted for the Regional Inventory JSF application, you should be able to figure out the appropriate method to invoke (action) as well as the appropriate JSF phase.
The view components (XHTML files) responsible for editing or updating an EmployeeDTO model object selected from the list need a way to communicate between pages. JSF maintains a Map
…
“list-employee.xhtml”; …
package com.algonquincollege.cst8277.controllers;
…
public class EmployeeController implements Serializable {
private static final long serialVersionUID = 1L; …
public String editEmployee(EmployeeDTO emp) { sessionMap.put(“editEmployee”, emp); return “edit-employee?faces-redirect=true”;
}
The editEmployee method registers the selected employee model object in the sessionMap using the (key) string “editEmployee”. In the scope of the returned view component “edit- employees.xhtml” , the key “editEmployee” is in-scope so one can just refer to it:
Address Book Application
Please review in the Deitel-&-Deitel supplementary files (specifically Chap 31), section 31.1 describes an Address Book application whose layout and behaviour is quite similar to our Employee Directory application.
fin.