20WCST8277 Enterprise Application Programming
Assignment 1
Please read this document carefully if your submission does not meet the requirements as stated here, you may lose marks even though your program runs. Additionally, this assignment is also a teaching opportunity material presented here in this document will be on Midterms and the Final Exam!
Assignment 1s submission is to be uploaded to the Assignment1 Brightspace submission folder. It does not matter if it is a zipfile containing a zipfile containing … manylevelsofnested zipfiles or if you upload the required artifacts individually, Brightspace will handle things. If you have a 100 perfect solution but it is not in the correct folder, you will receive a mark of zero If you know that you made mistake, please upload it to the correct folder ASAP.
Theme for Assignment 1
After completing this assignment, you will have achieved the following:
1. Created a DTO Model class to represent a DB row
2. Created a Managed Bean class to manipulate above Model class
3. Created a DAO class to manipulate the database
4. Created a JSF Application that supports Create Read Update Delete lifecycle for instances of the Model class
1
Grading for Assignment 1
There is a Brightspace Rubric that describes the marking scheme for this assignment:
2
Starting Assignment 1
You must use the file from Brightspace 20WAssignment1starter.zip to start your solution extract its contents to some work folder on your hard drive. Before you import the project into Eclipse, please change the name of the project to include your Student name and number this is done in two places. Open the file pom.xml in a regular texteditor eg. Notepad and find the name entry close to the top of the file:
Additionally in the folder srcmainresource, there is a file called Bundle.properties which contains constants used in the UI please change the default values for:
Your name should be as it appears in ACSIS.
A bundle is bound to a variable in JSF using the tag f:loadBundle:
groupIdcom.algonquincollege.cst8277groupId artifactIdemployeeDirectoryJSFartifactId version0.0.1SNAPSHOTversion
packagingwarpackaging name040123456Assignment1StudentNamename ! no spaces
footer.labsectionSection 123 footer.studentnumber040123456 footer.studentnameJane Doe
?xml version1.0 encodingISO88591 ? !DOCTYPE html
html langen
xmlnshttp:www.w3.org1999xhtml xmlns:fhttp:xmlns.jcp.orgjsfcore xmlns:chttp:xmlns.jcp.orgjspjstlcore
f:loadBundle basenameBundle varuiconsts
! view that lists all employees
However, since we need to load it at the top of multiple files e.g. listemployees.xhtml, addemployee.xhtml, etc., it is more convient to declare it in the facesconfig.xml file:
?xml version1.0 encodingUTF8? facesconfig
xmlnshttp:xmlns.jcp.orgxmlnsjavaee xmlns:xsihttp:www.w3.org2001XMLSchemainstance xsi:schemaLocationhttp:xmlns.jcp.orgxmlnsjavaee
http:xmlns.jcp.orgxmlnsjavaeewebfacesconfig23.xsd version2.3
application
resourcebundle
basenameBundlebasename
varuiconstsvar
resourcebundle
application
facesconfig
3
The starter project is an Eclipse Maven project. There is a screencast on Brightspace that shows how to import an existing Maven project into Eclipse Note: it is from an earlier version of the course but it is still relevant choose the Existing Maven Projects import wizard
4
When you import the project, there is an Advanced setting that you need to navigate to in order to use the name template:
Create employee table on database using DBeaver an Eclipse Perspective
In the Scripts folder, there is a file called employeeDDL.sql there are some special fields that are not used in this assignment but will be used in Assignment 2:
CREATE TABLE employee
id int IDENTITY not null,
createddate timestamp
5
Submitting Assignment 1
Your submission must include:
Code completed project that compiles, has good indenting, not overly complicated and
is efficient
o thecodemustdemonstrateyourunderstandingofhowaJSFApplicationworks
Eclipse has an export function to create an external archive i.e. a zip file of your project. You must export the project to a file that follows the same naming conventions we used in the pom.xml: 040123456Assignment1StudentName.zip.
Code style: every class method and every member field needs Javadoc comments. Here are some example Javadocs:
public class Simple
String name
private String name;
Constructor param name
public SimpleString aName this.name aName;
Every class file has a multiline comment block at the top giving the name of the file and typically the Instructors name, too you must add your Student Name and number:
File: EmployeeDaoImpl.java
Course materials 20W CST 8277
author original Prof. Mike Norman
author John Smith 040123456
o ImportantyournamemustappearatthetopofeachandeveryJavasource code file submitted otherwise you will lose marks for the coding portion of the Rubric
o YoushouldNOTtodothisatthetopoftheXHTMLfilesinfact,anyadditional artifacts at the top of those files will make the project fail to deploy
6
a Test Plan: this is a paper test plan, not actual running JUnit tests. Please submit a Word document that follows the following template:
Testcase Description
Pre Conditions
Post Conditions
Test methodology
Expected
Actual
1
Is something taking place?
…
…
How do you find out if something worked? Describe …
Should be …
Actually is …
2
…
8
o DescribetestsfortheDAOImplclassseebelow,andControllerclass minimum 4 test cases rows and no, you cannot reuse that first row!
o Importantnotfollowingthetemplatewillresultinlossofmarksuptoascoreof 0 for that part of the Rubric
Running Assignment 1
You may notice if you try to run the starter project unchanged, it does not show any employees
that is done on purpose:
You must find and fix the problems and extend the project to provide full CRUD capabilities:
7
Data Access Object DAO Data Transfer Object DTO
Java EE There is a pattern for Data Access Objects DAOData Transfer Objects DTO classes. The following reference is a great introduction: http:ramj2ee.blogspot.in201308data accessobjectdesignpatternor.html
To connect the controller class with the DAO class, we can inject a reference into the controller class Java constructor:
public EmployeeControllerEmployeeDao employeeDao this.employeeDao employeeDao;
Note: we inject the Interface, not the implementation!
JSF Tips N Tricks
In the first JSF Presentation view XHMTL file listemployees.xhtml, you must update the h:viewAction widget with the appropriate information so that when the Application is about to update its model classes hint, hint JSF phases, all the employees are loaded from the database.
The controller class should be scoped to the HTTP Session so that there is only one instance for http:localhost:8080employeeslistemployees.xhtml and for navigating back forth to the addedit pages. If another Web browser or 2nd tab of the same browser connects, a second controller will be instantiated. Q: What is the appropriate scope for the DAOImpl class? for the DTO class?
The Presentation view XHTML files responsible for editing or updating a Model object selected from the list needs a way to communicate between pages. JSF maintains a sessionMap that can hold almost! any object Q: how is the sessionMap injected? A h:commandLink buttons action attribute can invoke a method on the controller class which can then put something special in the map:
listemployees.xhtml
Inject
…
h:commandLink actionemployeeController.doSomethingemp.id
h:commandLink
8
EmployeeController.java
listemployees.xhtml
This way, when the edit XHTML form is presented, the existing values are populated into the fields.
The add XHTML form requires the same sort of thing except that we do not wish to populate the add form with the information of the last selected entity: in that case, we put a entirely new empty employee object into the session map:
sessionMap.putnewEmployee, new EmployeeDTO; fin
…
public String doSomethingint empId
EmployeeDTO e1 employeeDao.readEmployeeByIdid; sessionMap.puteditEmployee, e1;
…
h:panelGrid columns2
h:outputLabel valueuiconstscolumnLabelFirstname h:inputText valueeditEmployee.firstName idfirstName
…
9