Now it is time to examine xhtml files. First of all, you need to have a welcome file list. Please add a figure like following;
<welcome-file-list> <welcome-file>SOMETHING-COMES-HERE.XHTML</welcome-file> </welcome-file-list>
You can find my web.xml file in jsfapplication/src/main/webapps/webinf.
Webapp folder is where you add your xhtml files.
-Right click to the webapps folder.
-Click HTML File
-Choose xhml file format then enter the name of the xhtml file. This will be where you write your html code with Primefaces themes.
We must be careful when we write tags. We must put h before tag names else the themes will not be seen. Such as;
<h:head> <title>ADD USER</title> </h:head>
In my xhtml files, i used panels, datatables, outputlabels, inputtexts, command buttons and select check boxes. You can find my xhtml files in jsfapplication/main/webapp.
Now let’s examine the necessary tables for our database. As i mentioned in my first article, there is a one-to-many relationship between a user and role. That is why i created a cross table that has the id of a user and the id of a role. The structure is
CREATE TABLE ( userId UNSIGNED_INT NOT NULL, roleId NOT NULL );
And we need the role table like following;
CREATE TABLE Roles( roleId INT PRIMARY KEY NOT NULL AUTO_INCREMENT, roleName VARCHAR(100) );
And for the users, we are going to use radcheck table.
For this relationship, i created an extra dao to manage the actions more efficiently.The queries for the cross table( the insertions and deletions) are done in this dao. And we use this table to get the roles of all the users. To prevent the dublicates, i used maps and sets in the dao of user.
Finally, i will explain the unit tests. First of all my reference book was junit recipes by rainsberger, a very straightforward textbook that explains how to write test classes of a jsf project.
First, you need to add Groovy plugin and dependencies.Add the dependency like following;
<dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>2.3.0</version> </dependency>
Add the plugin like following;
Go to Files-Settings-Plugins and if there is no groovy, please press + button to add Groovy.
After that you should be getting a package under your base package called groovy. That package will be the place for your test classes.
You can write test classes or methods for everything in your project. For constructors, functions, queries, objects, getters and setters, etc. The main idea is that you should test what is not supposed to happen. If it does, the test class is working; which means there is something wrong with your testcase.
The structure is easy. When you right click to your class and say create test, it will automatically be opened. Your test class should be extended to GroovyTestCase . And the return types of your functions will be in the format of
assertEquals(<expected parameter>,<actual parameter>)
You can examine my test classes that i have written for possible errors in jsfapplication/main/java/Groovy.
That will be all for my project. If you have any concerns, please reach out to me i would be happy to get the critizations from you. Enjoy your coding!