I am a lifelong student of computer science, music, and literature. In pursuit of those interests, I work by day as a programmer Chemical Abstracts Services, moonlight as the creator and curator of Mashed Code Magazine. review books for The Pragmatic Bookshelf and Manning and listen to a fascinating collection of music while performing all of my duties. I have specialized in working with web services and mastering various testing techniques and tools. I am finally done with formal education, having a B.A. in English from The Ohio State University and a M.S. in Computer Science from Franklin University. Nick is a DZone MVB and is not an employee of DZone and has posted 15 posts at DZone. You can read more from them at their website. View Full User Profile

How to setup FacesTrace

09.11.2011
| 4956 views |
  • submit to reddit

If you’ve ever been caught trying to debug a Java Server Faces (JSF) 1.0 or 1.1 problem you know that you either get the “stack trace from hell” or too little output – in either case you don’t have what you need to troubleshoot. The problems that produce no helpful output (the kind you usually use the <h:messages></h:messages> tag to output to your JSP) are the ones that can be especially tricky. Since JSF gives no indication as to what actually went wrong, you’re stuck with various and tedious debugging techniques to troubleshoot a problem that is originating within the JSF life cycle. Luckily, there is a handy tool to help see inside the black box that is the JSF life cycle. FacesTrace is a very simple tool that visualizes the steps in the JSF life cycle, which ones passed or failed, and how long each step took to execute.

I believe that FacesTrace used to be a stand-alone tool but now is part of the PrimeFaces framework. I could not find a download of just FacesTrace anywhere on that site though, which was very confusing. I downloaded the PrimeFaces framework but it was devoid of anything specifically related to FacesTrace. I did find that you can download the facestrace.jar from SourceForge, which is where I suggest you get it from. The version this blog is based on is 1.0.1.

David Geary and Cay Horstmann recommend FacesTrace in their book Core JavaServer Faces 2nd Edition, but they’re missing a few steps in the setup. Even so, the full setup is dead simple. I couldn’t find that anyone else had documented it, so I’ve done that here. The steps are below. I’m assuming you’re familiar with a JSF application and you just want to use FacesTrace in it.

  1. Download facestrace.jar from here.
  2. Copy facestrace.jar to the WEB-INF/lib folder of your web app.
  3. Extract facestrace.js from the facestrace.jar to where you store JavaScript files in your web app.
  4. Extract facesTrace.css from the facestrace.jar to where you store CSS files in your web app.

That’s it for the setup. Now you can use FacesTrace in any of your JSF pages with a couple more easy steps. The steps below specify things you must add to each JSP in which you want to use FacesTrace.

1.  Add the FacesTrace taglib:

<%@ taglib uri="http://facestrace.sourceforge.net" prefix="ft" %>

2.  Link to the FacesTrace CSS file (use the location specific to where you extracted the file):

<link href="<%=request.getContextPath()%>/theme/facesTrace.css" rel="stylesheet" type="text/css">

3.   Link to the FacesTrace JavaScript file (use the location specific to where you extracted the file):

<script type="text/javascript" language="JavaScript" src="<%=request.getContextPath()%>/scripts/facestrace.js"></script>

4.  Add the FacesTrace trace tag in an appropriate place on your JSP page:

<ft:trace></ft:trace>

When you run your app and navigate to the page where you enabled FacesTrace you’ll see something like the image below:

The green boxes under the “Request Lifecycle” header represent the major steps in JSF’s lifecycle. Notice that each box contains the name of the lifecycle step and how long it took to execute. Boxes are green if the step succeeded and red if they did not.

The blue headers are clickable and will expand when clicked on. Another cool feature is under the “Component Tree” heading. Under this you can explore the JSF component model for the page, complete with component id’s and values. An example is below.

The rest of the interface is self-explanatory. I haven’t used FacesTrace much yet, but it’s worth adding to your app just in case you need it. If nothing else, playing around with it for some time will enhance your understanding of JSF!

As always, if I’ve been unclear, left something out, or you have some other question, please leave a comment on this post and I will respond soon.

 

From http://thewonggei.wordpress.com/2011/03/25/how-to-setup-facestrace/

Published at DZone with permission of Nick Watts, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Henk De Boer replied on Mon, 2011/09/12 - 4:28pm

People should really not be using JSF 1.0 and 1.1 anymore. Stuff like <%@ taglib uri="http://facestrace.sourceforge.net" prefix="ft" %> is just wrong...

Please, do yourself a favor and use at least JSF 2.0. FacesTrace does look nice really, although the development mode of JSF 2.x already prints something similar.

Nick Watts replied on Mon, 2011/09/19 - 1:38pm in response to: Henk De Boer

I appreciate the advice, but there are many other developers, like me, that are not able to upgrade for many reasons. In my case, I'm tied to the version of JSF that is supported by IBM, which is JSF 1.2 for WebSphere Application Server 7. So, wrong or not, my advice applies to anyone stuck with the older way of doing things, which was my only intent here.

John David replied on Wed, 2011/12/28 - 11:13am

You should now upgrade to JSF 2.0. It has lot more better performance and many bugs are fixed which were in last version.

Also you can deploy your application in JBoss as well.

Nick Watts replied on Tue, 2012/01/17 - 4:50pm in response to: John David

See my previous comment. This posting was intended to help people who do not have an upgrade as an immediate option. Upgrading or moving to a new container vendor is a very non-trivial decision to make.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.