JSF


Java EE 6 Is Here

Like Christmas come early, Sun announced the release of JEE 6. This release sees continued improvement in the JEE stack with the inclusion of JSR 299, Java Contexts and Dependency Injection (CDI), and EJB 3.1 as well as JSF 2.0, and JPA 2.0. JSF especially has seen changes as a result of practical user feedback and community add-ons such as Seam and JSF Ajax frameworks which have contributed back to the JCP.

Glassfish v3 which implements the full JEE 6 stack has also been released, with JBoss’ Weld as the CDI implementation. Netbeans 6.8 has also been released with full JEE 6 project support including maven support for enterprise applications. Also of note is the hot deploy function of Glassfish which can deploy your app while maintaining session information.

Personally, I’m pleased. JEE 6 has really improved things for the java standards, and CDI has filled some gaps that previously required different additional pieces to completely fill. The ghosts of EJB 2.1 should now be permanently laid to rest, but should serve as a stark reminder. Having good frameworks to build standards based solutions is always good for the community.

I’ll try and get some tutorials on developing with CDI and JSF 2.0 with Netbeans and Glassfish out soon.

Conversational Pitfalls

Seam conversations have certain rules that you need to be aware of when using them. This article came about because for the last couple of years, the same questions have been asked on the Seam forums regarding conversations. It is also a couple of issues that cropped up while I was working on the Seam vs. Spring Web Flow articles. Some of the problems are uncannily similar with similar solutions, so parts of this series may be of interest to non-Seam users. Additionally, it seems like a lot of this stuff will also apply to the conversational pieces of JSR 299 – Contexts and Dependency Injection which will be a part of JEE 6.
Read More »

Notes On Choosing A Web Framework

I’m looking at starting a new project and once again find myself choosing between frameworks. Having spent some time evaluating different ones I wrote up some notes to share and get some feedback that might alter my thoughts or opinions. Here’s the criteria I’m using to choose a framework in no particular order.
Read More »

Timing JSF Requests Using a Phase Listener

One easy way of determining how long it takes to return a page from Seam, and/or JSF is to use a phase listener. This phase listener below logs the end of each phase of the JSF lifecycle and measures the time from the start of the RESTORE_VIEW phase (the first phase in the lifecycle and the start of the request) to the end of the RENDER_RESPONSE phase which is the last one. Logging the end of each stage of the cycle lets you see what else is going on during each phase of the cycle.

public class LogPhaseListener implements PhaseListener {

	public long startTime;

	private static final LogProvider log = Logging
			.getLogProvider(LogPhaseListener.class);

	public void afterPhase(PhaseEvent event) {
		if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
			long endTime = System.nanoTime();
			long diffMs = (long) ((endTime - startTime) * 0.000001);
			if (log.isDebugEnabled()) {
				log.debug("Execution Time = " + diffMs + "ms");
			}
		}
		if (log.isDebugEnabled()) {
			log.debug("Executed Phase " + event.getPhaseId());
		}
	}

	public void beforePhase(PhaseEvent event) {

		if (event.getPhaseId() == PhaseId.RESTORE_VIEW) {
			startTime = System.nanoTime();
		}
	}

	public PhaseId getPhaseId() {
		return PhaseId.ANY_PHASE;
	}

}

To use this, simply add the class to your project and insert a new phase listener in the faces-config.xml file.

  <lifecycle>
    <phase-listener>package.name.LogPhaseListener</phase-listener>
  </lifecycle>

While it may not be totally accurate, it at least gives you an idea of the scale of the duration of a request (i.e. 68ms versus 394ms). I’ve used this fairly effectively in a few projects to cut out some bottlenecks as well as comparing and contrasting different JSF frameworks.

Creating A Spring Web Flow JSF Project From Scratch

(Updated – 9 August 2010 – This was written in my pre-Maven days and after a few requests for working source, I’ve built the same project using Maven which can be downloaded. Just unzip the maven project, go to the directory in the command line and type mvn jetty:run to start the server and deploy the project. Navigate to http://localhost:8080/swfproject/home.jsf or http://localhost:8080/swfproject/spring/testFlow to see the pages demonstrated in the tutorial.

I recently had to start another project using Spring Web Flow and found myself banging my head against a brick wall to get the web flow stuff set up and to request the page properly. As a result, I decided to write up my results as a quick how-to for other developers should they find themselves in the same situation and also as a reference for myself the next time I need to start a Spring Web Flow project using Spring Faces from scratch.This article is meant more of a “here’s-how” as opposed to a “how-to” or an “explain-why” so we’ll move at a quick pace with little explanation.
Read More »

Codeless Ajax Ordered and Paginated Tables in Seam

(Update : fixed some of the missing images)

One common code pattern that we find ourselves writing time and again is the ability to display tables which are paginated and sortable. Ideally, this is something we should try and be able to re-use throughout our application.

Current Situation

Let’s start by looking at where we are now with the features that come with Seam out of the box. In particular, we will be looking at the dataScroller component and the EntityQuery object. Read More »