Monday, April 27, 2009

The Simplest JSF Program You Can Write


So, I was just wondering how simply can you make a JSF application. I mean, every time a RAD tool creates a JSF project, all sorts of entries get populated in the web.xml and faces-config.xml file. But how many of those entries can you do without?

So, I decided to use IBM’s Rational Application Developer and strip out all of the superfluous stuff from the various xml and configuration files, and just have the FacesServlet invoke a very innocuous JSP file sitting in the root of the web application.

Here’s the simple deployment descriptor for the web module, the web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">
    <servlet id="JSF_Front_Controller_Servlet">
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-name>Faces Servlet</servlet-name>

And here’s the faces-config.xml file. I really didn’t think it could get this small, but apparently, you really just need it there. If you’re not using any JSF components or managed beans, you don’t need to have anything inside of it!

<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"



And here’s the handsome JSP page. There’s actually probably more here than I really need, with the doctype and everything, and even the custom tag – it’s not totally needed, but at least it definitively asserts that indeed, we have a JSF page, and not just a JSP.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<%@taglib uri="" prefix="f"%>
<title>Simple JSF Page</title>

    <p>Hello World!</p>

Actually, I tested the whole thing with just this for the html/jsp page, and it all worked just fine. Not the best form, granted, but it works! Sometimes, simple is best when you’re just starting out.

<head><title>Simple JSF Page</title></head>
    Hello World!

jsf hello world example irad websphere java server faces

No comments:

Post a Comment