Questions tagged [facelets]

Facelets is an XML-based view technology for the JavaServer Faces framework. You don't need to use this tag on every single JSF question where Facelets is "coincidentally" used as view technology. Use this tag only and only if you have a specific question or problem with Facelets' own tags.

Facelets

Facelets is an XML-based view technology for the JavaServer Faces framework. Designed specifically for JSF, Facelets is intended to be a simpler and more powerful alternative to JSP-based views. Initially a separate project, the technology was standardized as part of JSF 2.0 and Java-EE 6 and has deprecated JSP. Almost all JSF 2.0 targeted component libraries do not support JSP anymore, but only Facelets.

Hello World

Preparing: Depending on the server used, JSF/Facelets may already be built-in (GlassFish, JBoss AS, WebSphere, etc.), or not (Tomcat, Jetty, etc.). If not, then you'd need to download a JSF implementation to your choice and drop the necessary JAR files in /WEB-INF/lib folder.

Controller: First register the FacesServlet in /WEB-INF/web.xml as follows:

<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

View: Then create a Facelets file hello.xhtml as follows:

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Facelets</title>
    </h:head>
    <h:body>
        <h:form>
            <h:inputText value="#{sessionScope.who}" />
            <h:commandButton value="Say Hello" />
        </h:form>
        <h:outputText rendered="#{sessionScope.who != null}"
                      value="Hello, #{sessionScope.who}" />
    </h:body>
</html>

Start the server and open it by http://localhost:8080/contextname/hello.xhtml.

Model: if you also want to create the model, then head to JSF tag wiki.

Documentation

Online resources

Frequently asked questions

Related tag info pages

1820 questions
235
votes
2 answers

How to include another XHTML in XHTML using JSF 2.0 Facelets?

What is the most correct way to include another XHTML page in an XHTML page? I have been trying different ways, none of them are working.
Ikthiander
  • 3,917
  • 8
  • 37
  • 54
176
votes
3 answers

JSTL in JSF2 Facelets... makes sense?

I would like to output a bit of Facelets code conditionally. For that purpose, the JSTL tags seem to work fine: ... However, I'm not sure if this is a best practice? Is there another way to achieve my goal?
Jan
  • 9,397
  • 13
  • 47
  • 52
113
votes
6 answers

The entity name must immediately follow the '&' in the entity reference

I want to put a packman game on my *.xhtml page.(I am using jsf 2 and primefaces 3.5) However, when I "translated" the html page in xhtml I get an error at this script: