Jsf – Facelets – Richfaces. part 1
It’s almost 2 months I did’nt update my blog
. Here we go. As the title suggest, I want to write about Jsf, Facelets, and Richfaces. But for as part 1 of all (don’t know the exact number hahaha) I’m just writing about preparation that is tools and resources needed to make simple things simple. It’s ok if you don’t know what all of this stuffs (jsf, facelets and richfaces) because soon we’ll understand by learning
. Let’s go!
Here’s tools required and used to make our work simple. Download and install.
- JDK 1.6, always needed because we’re learning java right?
- Netbeans 6.5, JEE version
- facelets support for netbeans 6.5
- richfaces support and palette for netbeans 6.5
To install facelets support, richfaces support and palette go to Tools – Plugins in netbeans, open Downloaded tab and click “Add Plugins..” button, select all .nbm files downloaded and click “Install”.
Now we’re ready to create Jsf – Facelets – Richfaces project. Follow these steps:
- Create New Project (Ctrl+Shift+N), select Java Web Category and select Web Application Project and click Next
- Set Project name and location and click Next
- Make sure we are using GlassFish as application server and click Next
- Check Facelets and Richfaces option at Framework selection and click Finish.
- Now project artifacts is automatically generated and we’re ready to make a bit changes.
- Open web.xml file and change its content with below:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- Jsf params --> <context-param> <param-name>com.sun.faces.verifyObjects</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>com.sun.faces.validateXml</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param> <!-- Facelets params --> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param> <context-param> <param-name>facelets.DEVELOPMENT</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>facelets.SKIP_COMMENTS</param-name> <param-value>true</param-value> </context-param> <!-- Richfaces --> <context-param> <param-name>org.richfaces.SKIN</param-name> <param-value>blueSky</param-value> </context-param> <filter> <display-name>RichFaces Filter</display-name> <filter-name>richfaces</filter-name> <filter-class>org.ajax4jsf.Filter</filter-class> </filter> <filter-mapping> <filter-name>richfaces</filter-name> <servlet-name>Faces Servlet</servlet-name> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <!-- Faces Servlet --> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <!-- Faces Servlet Mapping --> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> </web-app> - Open faces-config.xml and change its content with below:
<?xml version='1.0' encoding='UTF-8'?> <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"> <application> <view-handler> com.sun.facelets.FaceletViewHandler </view-handler> </application> </faces-config> - Delete all generated java code and its corresponding package by right clicking at org.my.richfaces and click delete.
- Rename forward.jsp to index.jsp
- Try to run project by clicking project and click Run.
Till this point we are ready to code nitty gritty stuffs but there are some problems with the plugins (google it and you’ll find some). First, autocomplete doesn’t work as expected (try to type “<ui” in .xhtml file). Second, if we open .xhtml file then A4J and RichFaces palette won’t appear (they appear if you open .jsp file). Okay, let’s fix this.
Problem 1, richfaces support (plugins) includes richfaces 3.3.0 library, it’s causing problem to netbeans parser, let’s change this to richfaces 3.2.1.
- Download richfaces 3.2.1, extract.
- Change richfaces library in netbeans by opening Tools – Libraries, select RichFaces.
- Remove richfaces-api-3.3.0, richfaces-impl-3.3.0 and richfaces-ui-3.3.0.
- Add richfaces-api-3.2.1, richfaces-impl-3.2.1 and richfaces-ui-3.2.1 jar file from lib folder of the extracted file.
- click OK to close Library Manager.
- Now try to type “<ui” in .xhtml file, autocomplete should be work as expected.
Problem 2, A4J and RichFaces palette for .xhtml file. This technique is a bit tricky
- Open Palette Manager for jsp file by opening menu Tools – Palette – HTML/JSP Code Clips
- expand A4J and select all its child then drag to HTML
- close Palette Manager
- Open Palette Manager for xhtml file by opening menu Tools – Palette – Facelets Code Clips
- Create new category and name it A4J
- expand HTML and select all a4j component then drag to A4J
- close Palette Manager.
- Do step 1 to 7 for RichFaces tag
- Open Palette Manager for jsp file (as step 1) and click Reset Palette.
Now, .jsp and .xhtml file have A4J and RichFaces at its Palette and we are ready for coding
. But before we do let’s take a quick review at developer documentation and taglibs for each framework so we can get familiar with it.
JSF.
Facelets is a view template for jsf, we won’t need jsp
.
Richfaces is one of component library for jsf. Find more about component library at jsfmatrix
- RichFaces Developer Guide, available at docs folder from the extracted file
- RichFaces showcase or you can download and run in your own computer.
Happy programming!
Exactly what i needed. Very detailed. Great Job. Thank you so much.
Best regards
Riepi
Riepi
October 28, 2009 at 3:51 pm
I find that I never had a problem with the autocomplete for tags, which work regardless of whether I have the current libs or the 3.2.1 libs (for the record, the current are 3.3.2.SR1 at this time).
However I cannot get autocomplete to work for the tags in either case!
Any ideas?
The palette fix works great.
Robert
December 12, 2009 at 3:06 am
I cannot get autocomplete to work for the tags, in any case.
Sorry, had a momentary typing dyslexia
Robert
December 12, 2009 at 3:07 am
I cannot get the autocomplete to work for the tags prefixed with the “rich:” namespace.
It appears my typing problem was the comment engine, which deletes anything formatted like a tag from the message text.
Robert
December 12, 2009 at 3:10 am