Seam


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.

Spring vs Seam Part 4 – Coming Soon (honest)

I know it has been a while since I pushed out my last piece on Spring Web Flow vs Seam, but I am still trying to get it ready. With Christmas, software releases at work leading to a hectic work schedule, and other stuff I have limited time. Furthermore, I am still re-writing parts of it, and I end up digressing into related info that is not central to the piece. Also, I am still having difficulty accurately writing up the final conclusion in a fair, and informed manner.
However, hopefully, I will get it completed in the next week here and I can get it released. I may also have some additional material for blog posts.

Seam versus Spring Web Flow part 1

This is the first of a four part series comparing Seam and Spring Web Flow (SWF) from different aspects, primarily with respect to building web based CRUD applications. It includes writing a simple but fairly complete application using both frameworks and then comparing the differences between the Seam and the SWF implementation.

This first part starts by taking a look at the two frameworks, where they come from and briefly, how they are used.

(Updated 1/19/2009 : Changed links to point to the whole set of articles)
HTML
Single Page HTML
PDF

In defence of hidden fields with Seam

In this post about pagination with Seam entity queries, I outline a method to encapsulate the pagination mechanism in a facelet that internally uses hidden fields to hold the state. Alexander R?hl pointed out that Dan Allen in his book Seam In Action recommends avoiding hidden fields in favor of page parameters lest they become a tangled mess. It’s a fair point, and one that probably deserves a better answer than a brief post comment. Read More »