Skip to main content

Another Small Step for JSF...

Posted by cayhorstmann on October 19, 2009 at 11:56 AM PDT

In the relentless fight against configuration boilerplate, JSF and Glassfish have taken yet another small step forward. As of Glassfish v3 build 68, you no longer need to declare the faces-servlet in WEB.XML.

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

In fact, you can omit web.xml altogether, except then you don't get to set javax.faces.PROJECT_STAGE to Development. (Since I am a developer, I think it's too bad that's not the default.)

GlassFish automatically provides a JSF servlet mapping for the /faces/*, *.faces, and *.jsf patterns, provided that any of the following conditions applies:

  • Any of the classes in the web application uses a JSF 2.0 annotation
  • Any initialization parameters start with javax.faces
  • The WEB-INF/faces-config.xml file is present

Isn't it grand? Now you can have a JSF app without web.xml or faces-config.xml, just a bunch of .xhtml pages and Java classes annotated with @ManagedBean.

The only fly in the ointment is that, if you really want to be thoroughly modern and use web beans, erm, JSR 299 Contexts and Dependency Injection, then you should still leave something in place to trigger the servlet mapping.

Another nifty step forward: NetBeans 6.8 Milestone 2 now does autocompletion on JSF 2.0 facelets pages, including tags, attributes and even EL expressions.

For example, here, Netbeans has found a @ManagedBean(name="user") and located name and password properties.

It might be a good idea to filter out the useless Object methods—when is the last time you wanted to call notifyAll in an EL expression? Or worse, wait :-)

After EE5 came out, I did all my EE development in Netbeans. It gave me one-stop shopping, bundling everything that I needed in a single download. I moved to Eclipse when Netbeans couldn't deal with EE6 improvements such as the simplified packaging. It worked in Eclipse (out of ignorance, not some grand plan), and that's what I used for the last 12 months or so. I was reasonably satisfied, thanks to the Glassfish Eclipse plugin, but Eclipse's support for editing JSF pages is extremely basic. Now I am very tempted to go back to Netbeans—I am a sucker for autocompletion.

Related Topics >>

Comments

eclipse & auto-completion

I'm new to JSF, and using Eclipse 3.5 / Galileo. I get auto-completion from the 'Web Page Editor'. You can 'Open With' or go to preferences / general / editor / file associations to set the 'Web Page Editor' as default for jsf / jsp files. regards,

I love the lego picture...

I love the lego picture...

Core JavaServer Faces update?

Cay, I'm wondering if you will be coming out with a new version of Core JavaServer Faces sometime soon that's been updated for JSF 2? Jon