Dear Impesud Network,
I hope this message finds you well and in good spirits. Today, I’d like to share with you the exciting realm of developing advanced web applications using JavaServer Faces (JSF) and PrimeFaces, backed by Jakarta EE 10.
This third newsletter dedicated to Jakarta EE 10 takes up the developed code and is the continuation of:
Hands-On Guide to Jakarta EE 10 with Payara
Empowering Jakarta EE 10: Seamless Integration with MySQL for Robust Applications
The code for this article can be downloaded from: https://github.com/Impesud/jakartaEE10/tree/main/jakarta10-jsf-primefaces
Overview of the Technologies
Jakarta EE (Enterprise Edition):
Jakarta EE 10 stands as the latest milestone in the world of Java enterprise development. With advanced features and improved compatibility, Jakarta EE 10 provides a robust foundation for building complex and scalable web applications.
Jakarta Server Pages (JSF):
JavaServer Faces simplifies the web user interface development process through its component-based programming model. With a managed lifecycle, JSF reduces the complexity of frontend development, allowing you to focus on creating extraordinary user experiences.
PrimeFaces:
PrimeFaces, the component library for JSF, further enriches page design possibilities. From interactive widgets to customizable themes, PrimeFaces offers a wide array of tools that simplify the creation of modern and captivating user interfaces.
Product List with PrimeFaces
Let’s see how to effortlessly create a product list using PrimeFaces. Components like simplify the display and interaction with data, providing a tangible example of development dynamics.
Updating pom.xml
This code snippet is a Maven dependency configuration for integrating PrimeFaces into a Jakarta EE project.
1
2
3
4
5
6
|
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>13.0.4</version>
<classifier>jakarta</classifier>
</dependency>
|
Updating web.xml
The provided code is a part of the configuration for setting up JavaServer Faces (JSF) using the Servlet API, and it specifies that requests with the “.xhtml” extension should be processed by this servlet.
1
2
3
4
5
6
7
8
9
10
|
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
|
Updating bean.xml
Update the file specifically for configuring CDI (Contexts and Dependency Injection) in Jakarta EE. In this case, “all” means that CDI will discover all beans in the application.
1
2
3
4
5
|
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
bean-discovery-mode="all"
version="4.0">
</beans>
|
Creating ProductBean file
This Java class serves as a managed bean in a Jakarta EE application, intended for handling product-related data. It uses CDI for dependency injection, specifies a request scope to manage the bean’s lifecycle, and initializes the product data during the post-construction phase. The getProducts() method allows external components to retrieve the list of products.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
@Named
@RequestScoped
public class ProductBean {
@Inject
private ProductService productService;
private List<Product> products;
@PostConstruct
public void init() {
products = productService.findAll();
}
public List<Product> getProducts() {
return products;
}
}
|
Updating index file
Rename index.html to index.xhtml. This XHTML file serves as the view for a web page in a Jakarta EE 10 application. It leverages JSF and PrimeFaces components to create a dynamic and interactive page displaying a list of products with their details. Styling is applied through an external CSS file, and the page structure follows the conventions of JSF.
You should get:
Conclusion
The synergistic use of JSF and PrimeFaces with Jakarta EE 10 offers an advanced development environment for web applications. This robust and comprehensive combination allows you to build powerful, intuitive and future-ready applications.
If you are interested in exploring these technologies further or would like assistance implementing similar solutions in your project, please do not hesitate to contact me. I’m here to share knowledge and experiences. Contact us: https://www.impesud.it/contatti/ (parliamo italiano, hablamos español, speak English).
Subscribe on LinkedIn