JBoss.orgCommunity Documentation
In this chapter, we demonstrate the world's simplest JSF "Hello World" application.
Go to your JBOSS_HOME/server/default/deploy
directory and create these two subdirectories:
hellojsf.war
hellojsf.war/WEB-INF
This web.xml
only needs the minimum
declarations shown below. Place the file in /WEB-INF
.
<?xml version="1.0"?> <web-app> </web-app>
This faces-config.xml
only needs the minimum
declarations shown below. Place the file in /WEB-INF
.
<faces-config 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_2_0.xsd" version="2.0"> </faces-config>
The faces-config.xml is only there to signal to JBoss AS that this is a JSF application. There are many other ways that JBoss AS6 could recognize this as a JSF application. This is explained in detail in chapter 3.
We will use a single facelet. Create the file index.xhtml
and put it in your deploy/hellojsf.war
directory.
We use a little JSF2/EL 2.2 trick to avoid the need for a backing bean. We can grab the input value directly from the request object using a parameterized EL expression.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <f:view> <h:form id="form1"> <h:outputText value="Enter Your Name:"/> <h:inputText id="name"/> <h:commandButton value="Submit" /> </h:form> <h:outputText rendered="#{not empty request.getParameter('form1:name')}" value=" Hello #{request.getParameter('form1:name')}"/> </f:view> </html>
Now we're done! We only needed three files and two of those were just placeholders.
Start JBoss AS6 and put any of the following URLs into your browswer: