JSF Versus JSP, Which One Fits Your CRUD Application Needs? (Part 2)
Join the DZone community and get the full member experience.
Join For FreeCRUD (Create Read Update Delete) applications are high demanded by clients and usually require addressing functionalities like:
- Easy handling of insert/update/delete of records (as their naming states)
- Privilege control system, a role based one.
- Input validation
- Means to support handling the standard set of entity relantionships: one-to-many, many-to-many.
- Internationalization
- Provide a rapid response after a request was sent etc.
Stage 1 - Setup the development environment
This phase is common to both projects and only the dependencies included in the MAVEN pom files differ.
- Register the development server in the IDE
- Create a Maven web project in the IDE
- Run the web project from the IDE (test compilation, deployment, run capabilities, get the necessary dependencies and ensure interoperability between IDE, server and browser)
- Register the database server in the IDE (I attached an sql file as a data model to this article). I used Apache Derby database.
- Establish a connection to the database server from the IDE.
- Create a database instance on the database server.
Stage 2 - Prepare data model
In this stage the following activities are included :
- Create an entity-relationship diagram (use a visual database design tool)
- Identify objects
- Create a schema
- Create entities
- Add entity properties
- Identify relationships between entities
- Forward-engineer the entity-relationship diagram into an SQL script
- Run the script on the database server to generate the schema
For the two Proof of Concept projects there is already an sql script attached to this article. You can run that script in order to test the code attached.
Stage 3 - Connect the application to the database
- Add sample data to the database (inserts from the attached sql)
- Create data source and connection pool on server
- Test data source (ping connection pool)
- Ensure that views can access data from the database (if any views are defined)
- Set any necessary application-wide parameters
Stage 4 - Develop the business logic
CRUDwithJSF2.2 project |
CRUDwithJSP project |
Create entities from database tables.
Attention: 1. do not forget to add your entities to persistence.xml 2. even if your IDE automatically generates mapping pay attention to the OneToMany or ManyToOne relationship mapping |
Create data objects based on database tables.
|
Create AbstractFacade and its children DeparmentFacade and EmployeeFacade. These 3 classes will ease the invocation of changes on database. |
Create EmployeeDAO and DepartmentDAO that manipulate the database transactions for each of the data objects. Also, realise the database connection with an util class DatabaseUtil since that connection is shared for every type of object. |
Stage 5 - Create controllers
CRUDwithJSF2.2 project |
CRUDwithJSP project |
|
|
|
|
Stage 6 - Organize the application front-end
CRUDwithJSF2.2 project |
CRUDwithJSP project |
The JSFs can be generated, using templates. I used Create template . |
Place JSP pages in the application's WEB-INF directory |
Define page header and footer inside template.xhtml |
Create page header and footer |
When you using templates there is little chance of code duplication. |
Remove instances of code duplication (header and footer code from JSP pages) |
By using templates it is much easier to customize the style of the application and offer an uniform look to it. |
Unfortunatelly, for pure JSPs the UI customization is available by adding css files as for any other client web page. |
Stage 7 - Achieve Internationalization: add language support
CRUDwithJSF2.2 project |
CRUDwithJSP project |
In face-config.xml define your properties file that contains the labels. Place the Bundle under resources area of the web application. <application> <resource-bundle> <base-name>/Bundle</base-name> <var>bundle</var> </resource-bundle> </application> |
Place the localization file in web.xml and define it under WEB-INF folder in order to access it easily. <context-param> <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name> <param-value>lang</param-value> </context-param> |
Learn
Opinions expressed by DZone contributors are their own.
Trending
-
How To Manage Vulnerabilities in Modern Cloud-Native Applications
-
Cypress Tutorial: A Comprehensive Guide With Examples and Best Practices
-
Using OpenAI Embeddings Search With SingleStoreDB
-
Tactics and Strategies on Software Development: How To Reach Successful Software [Video]
Comments