How to Print HelloWorld using Primefaces in maven-based Java Web Application in NetBeans IDE

Posted on

Introduction

This article has a connection with several articles exist in previous. Those articles are the articles for creating a maven-based Java web application. The first one is the article with the title of ‘How to Create maven-based Web Application in NetBeans IDE’ in this link.That article is an example to create a simple Java web application by having to display only a single index HTML file printing ‘Hello World’. The second article is an article with the title of ‘How to Add JSF Library to a maven-based Web Application in NetBeans IDE’ and it is available in this link. On the other hand, the second article is already using a different file extension with the name of ‘index.xhtml’. Furthermore, it is also a simple web application which is printing a simple display of ‘Hello from Facelets’. The last or the third one is the article with the title of ‘How to Add Primefaces Library to a maven-based Java Web Application in NetBeans IDE’ where it is accessible in this link. But adding in it does not mean there is one file index is available for further execution using Primefaces library. There is an another additional effort to create a new file manually which is printing a UI component available from Primefaces library.

Introduction

So, in order to print a certain UI interface component available from Primefaces library, do the following steps :

  1. Since the example is using NetBeans IDE as a demonstration, just run NetBeans IDE first

  2. By default, there is two files already exist in WEB-INF folder. The first one is the ‘index.html’ file from the process for creating a new Java Web Application. It is available in the previous article before with the title of ‘How to Create maven-based Web Application in NetBeans IDE’ in this link. The second file is the ‘index.xhtml’ file from the adding a JSF framework library to the Java Web Application. That article with the title of ‘How to Add JSF Library to a maven-based Web Application in NetBeans IDE’ available in this link as a reference. So, in order to demonstrate how to print a certain UI component of Primefaces, just create a third file manually. For an example, ‘index-primefaces.html’. Put it in ‘WEB-INF’ folder with the following content :

    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://xmlns.jcp.org/jsf/html"
          xmlns:f="http://xmlns.jcp.org/jsf/core"
          xmlns:jsf="http://xmlns.jcp.org/jsf"
          xmlns:ui="http://xmlns.jscp.org/jsf/facelets"
          xmlns:p="http://primefaces.org/ui">
          <f:view contentType="text/html;charset=UTF-8" encoding="UTF-8">
             <h:head>
                 <h1>Hello World from Primefaces</h1>
                 <p:textEditor secure="false"/>
             </h:head>
    </html>

    The first one is just a simple string of ‘Hello World from Primefaces’ using the default tag header <h1>. The second one is the textEditor UI component from Primefaces library. It is important as an additional script just to prove that the Primefaces library is working in the ‘xhtml’ file.

  3. The following is the actual output after cleaning and building the Java web application and then running it :

    How to Print HelloWorld using Primefaces in maven-based Java Web Application in NetBeans IDE

Leave a Reply