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
- From "File" menu ⇒ choose "New Project...".
- "Choose Project" ⇒ Under "Categories", choose "Java Web" ⇒ Under "Projects", choose "Web Application" ⇒ "Next".
- "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. - "Server and settings" ⇒ Choose your server, or "add" a new server ⇒ Next.
- "Frameworks" ⇒ Check "JavaServer Faces" ⇒ In "Libraries", "Registered Libraries", select "JSF 2.0" ⇒ Finish.
- 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
- Right-click on the project ⇒ New ⇒ "Other..."
- "Choose File Type" ⇒ Under "Category", select "JavaServer Faces" ⇒ Under "File Type", select "JSF Page" ⇒ Next.
- "Name and Location" ⇒ In "File Name", enter "
HelloJSF20
" ⇒ In "Options", check "Facelets" ⇒ Finish. - 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>
- To execute the JSF page, right-click on the project ⇒ Run ⇒ Change the URL to
http://localhost:8080/HelloJSF20/HelloJSF20.xhtml
.