I’ve been using Oracle JDeveloper for the past few days for JSF development and I must say, that I quite like it. The visual editors are pretty good and do make you much more productive.
I do have a couple of issues though that I can’t seem to solve, and as the title says, they are pretty simple tasks.
  • First of all, I want to create a new folder underneath my public_html folder. There must be a way of doing this, but I can’t find it.
  • Secondly, I want to refactor some JSP files and move them into a different directory. Again, I can’t find a way of moving JSP files within the web application. Surely this can be done?
Since I started learning JSF, most of my development has been done in either NetBeans 5.5 or Eclipse 3.2. Whilse both of these are good IDE’s, they don’t provide any great visual support for JSF development.
Now that I understand the basics of JSF, I’m going to try using the features of the IDE more to become more productive – there’s no point learning a technology if it takes forever to write applications in it!! I still maintain that its useful to learn a technology using the bare basics (e.g. editing the faces config XML file manually), but when you’ve done that a few times it starts to get a bit repetative and boring and thats where a good IDE becomes useful.
I’ve decided to try using Oracle JDeveloper 10g. I initially wanted to use Sun’s Java Studio Creator, but had problems getting this to run under Java 5 on a Mac.
Initial impressions about JDeveloper seem to be good. It has a visual page flow editor together with a visual drag and drop page designer. I’ve managed to develop a few JSF applications (running internally on OC4J) and then deploy them externally to GlassFish without any major problems.
Are there any other visual JSF editors that other developers use? I’m quite happy with JDeveloper at the moment, but I’d be interested to hear what other developers use.
In his blog, Keith poses a question “Are you using JSF or intending to?”. So here goes, these are my reasons for learning JSF.
  1. The answer Keith didn’t want. It’s a standard. I know this is a very boring and possibly not very good reason, but I’m interested in the new Java EE 5 spec and JSF is a part of the new spec.
  2. I don’t know JSF yet. This may sound pretty obvious, but I want to learn JSF because I don’t know it. If I don’t know JSF well enough to develop applications in it, I can’t really say whether it is fit for the types of applications I develop or whether I should be using some other framework like Struts or Wicket or Spring MVC.
  3. I want to learn Seam. Seam is based upon JSF, so its probably a good idea to get a good grounding in the basics before progressing to the next stage.
  4. JSF will supposedly allow me to develop web apps quickly. Whether this is true or not, I’m sure I’ll soon find out!
So, will I ever deploy an application with JSF? I don’t know, I’m still in the early stages of learning. I know there is plenty of information on the internet regarding peoples opinions of various technologies including JSF, but how much of it is FUD and how much is reasoned criticism?
As usual, when learning a new technology, the first application to write is a "Hello World" style application. To continue this tradition, I've written a very simple Hello World JSF application. After setting up the Faces servlet as described in my previous post, I've written a simple JSP page called hello.jsp which has the following contents:
<%@page contentType="text/html"%> 
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<h:outputText value="Hello World" />
This simple JSP page specifies that the 2 JSF taglibs "core" and "html" are to be used and specifies their appropriate prefixes. The HTML is pretty standard up until the <f:view> tag. This tag tells the container we are going to start using JSF components. Inside this tag, the outputText component is used to print out the text "Hello World" to the browser.
This trivial application is started by pointing the browser to http://localhost:8080/LearningJSF/hello.jsf
In a previous post, I specified my JSF URL mapping as *.jsf . If however, you try to access the JSP page that contains the JSF code directly (e.g. browse to hello.jsp instead of hello.jsf), then JSF will throw an IllegalStateException. It took me a few minutes to work out what the exception means, but in this case the description is rather obvious.
java.lang.IllegalStateException: No FacesContext is available to process this request. 
This is most likely due to the request being sent to the wrong path.
I've just found a series of articles published on IBM Developer Works called "JSF for non believers" written by Richard Hightower. They seem to be a good tutorial into JSF.
There are 4 articles in the series namely:
Declaring the Faces servlet is the first necessary step in developing a JSF application. The following XML snippet (from WEB-INF/web.xml) allows the servlet to be declared and specifies that all requests ending in *.jsf are passed to the Faces servlet which routes them to the corresponding JSP page.
<servlet-name>Faces Servlet</servlet-name>
<servlet-name>Faces Servlet</servlet-name>
I've noticed that when you create a JSF project in NetBeans, a different servlet mapping is used. NetBeans creates a servlet mapping with a url-pattern of /faces/* as shown below:
<servlet-name>Faces Servlet</servlet-name>
I don't know if there is a standard convention to use here or if one is better than the other?
JSF applications need a JSF implementation to run. There seem to be a few of these about, most noticeably the Sun JSF Implementation and the Apache MyFaces JSF implementation.
The Sun implementation supports JSF 1.2 which is the latest version of JSF and part of the Java EE 5 specification. The Apache MyFacesimplementation supports JSF 1.1.
I'm interested in Java EE 5, so I'm going to start learning with the Sun implementation using the GlassFish application server using NetBeans 5.5 as my IDE.
I know NetBeans has a lot of wizards and helpers to allow experienced developers to write applications quicker, but since I'm learning I'm going to try and minimize the use of these wizards. I'm a firm believer of learning a topic first before I start to use IDE generated code. When I'm more proficient in JSF, I imagine the tools provided by IDEs will be invaluable.
This blog aims to help categorize my experiences whilst learning Java Server Faces (JSF).
My aim is to blog about the experiences I have whilst learning JSF, both good and bad. I'd be interested to hear from others who are either learning JSF, or who have learned JSF. If you have any sources of information which may be helpful (books, tutorials, web sites etc.), than I'd be interested in hearing about them.
I hope this blog will be both useful to me and to any others learning JSF.