Downloading and Installing NetBeans IDE

9. Developing and Deploying Web Application in NetBeans

9.4. Writing a Hello-world JSF 2.0 Web Application

Create a New JSF 2.0 Project

  1. From "File" menu ⇒ choose "New Project...".
  2. "Choose Project" ⇒ Under "Categories", choose "Java Web" ⇒ Under "Projects", choose "Web Application" ⇒ "Next".
  3. "Name and Location" ⇒ In "Project Name", enter "HelloJSF20" ⇒ In "Project Location", select a suitable directory to save your works ⇒ Check "Set as Main Project" ⇒ Next.
  4. "Server and settings" ⇒ Choose your server, or "add" a new server ⇒ Next.
  5. "Frameworks" ⇒ Check "JavaServer Faces" ⇒ In "Libraries", "Registered Libraries", select "JSF 2.0" ⇒ Finish.
  6. An "index.xhtml" JSF page is generated, as follows:
    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html">
        <h:head>
            <title>Facelet Title</title>
        </h:head>
        <h:body>
            Hello from Facelets
        </h:body>
    </html>    
    To run this facelet, right-click on the project ⇒ Run.

Create a new JSF 2.0 Facelet

  1. Right-click on the project ⇒ New ⇒ "Other..."
  2. "Choose File Type" ⇒ Under "Category", select "JavaServer Faces" ⇒ Under "File Type", select "JSF Page" ⇒ Next.
  3. "Name and Location" ⇒ In "File Name", enter "HelloJSF20" ⇒ In "Options", check "Facelets" ⇒ Finish.
  4. In "HelloJSF20.xhtml", enter the following codes:
    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html">
        <h:head>
            <title>Hello JSF 2.0</title>
        </h:head>
        <h:body>
           <h1>Hello from Facelets</h1>
        </h:body>
    </html>
  5. To execute the JSF page, right-click on the project ⇒ Run ⇒ Change the URL to http://localhost:8080/HelloJSF20/HelloJSF20.xhtml .