Thursday, May 31, 2012

The resolution of the Facelet taglib problem in jsp pages


Many of you have all ready encountered some problems while using facelets into a jsp page. Among them, you have probably seen this special error:  Cannot find the tag library descriptor for http://java.sun.com/jsf/facelets  although you have added the facelet taglib in the same way as shown below:
1.  <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
2.  <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
3.  <%@ taglib uri="http://java.sun.com/jsf/facelets" prefix="ui"%>
4.  <html>
5.  <head>
6.  <title>facelet example </title>
7.  </head>
8.  <body>
9.  Content
10. </body>
11. </html>
The explanation of this error is that using <% %> is equivalent to <jsp … and this is prohibited with facelets. So in order to get rid from this problem, you have to put the taglibs in the html tag like this:
<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:t="http://myfaces.apache.org/tomahawk"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core">
You can add as many taglibs as you want.