There are two ways to start a JSF application with RichFaces components with the NetBeans IDE. The first method is to create a simple JSF project within NetBeans, add RichFaces libraries and register RichFaces in web.xml. The second way is to create a Maven project, add JSF and RichFaces dependencies to its pom.xml, import the project into NetBeans, build it and run on the server. The following two examples demonstrate these methods.
The version of Maven used in the second example is 2.1.0.
1. Simple JSF application with RichFaces
Open NetBeans and create new project with JSF activated:
Navigate to File > New Project;
Select Java Web > Web Application and click Next;
Give the project a name, for example, testRichFaces;
On the next page configure the Tomcat 6 server and Java EE version (Java EE 5), press Next;
Check JavaServer Faces framework and click Finish to complete the project creation.
Now press F6 to run the server. In the browser you should see “JavaServer Faces”.
Next step is to add RichFaces libraries to the JSF project just created:
- Right-click the project and follow to Properties > Libraries > Add Library > Create.
- In the appeared dialog type RichFaces as the library name and select Components Libraries as the library type. Click OK.
- Select just created RichFaces library and click Add Library. Then press OK.
One more thing you need to do is to modify the web.xml, i.e. add filter mapping and skinning, as it's described in the RichFaces Developer guide.
Now you can use RichFaces components on the pages of your application. Let's add, for instance, the <rich:calendar> component to the welcomJSF.jsp:
Add the RichFaces tag library declaration at the top of the page:
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
Add <rich:calendar/> tag to the page.
Run the server again (F6). Now in the browser window you should see the calendar control under the “JavaServer Faces” caption.
2. JSF Maven Project with RichFaces
First, create a Maven project as it's described in the “Integration of RichFaces into Maven Project” section of the RichFaces Developer guide. Just don't build the project. You'll be able to easily do it in NetBeans IDE.
So next import the project to the NetBeans:
Follow to File > Open Project;
Select created jsf-app project and press Open Project.
Now right-click the project and select the Clean and Build option that will perform the Maven 'mvn clean install' command. After building the project open the web.xml to configure it according to the listing in the Registering RichFaces in web.xml section of the RichFaces Developer guide.
That's all. Now you can start using RichFaces components:
Add the tag library declaration at the top of the page and some RichFaces component, for instance, <rich:calendar>. The page should look like this:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%> <html> <head> <title>JSF Application with RichFaces built by Maven</title> </head> <body> <f:view> <rich:calendar /> </f:view> </body> </html>
Finally run the application by right-clicking the project and selecting Run. It will open the browser window with the RichFaces calendar.