One million dollar JSF Puzzle
March 1, 2006 5 Comments
Following puzzle came up to my mind yesterday when I was working on a new library that hopefuly will bring some traceability features to JSF. Here is the question:
Roni wants to measure how long each phase in the JSF lifecycle takes and then a custom component he has planned to implement will display the results on a page. In each phase, he saves the time at beforePhase and afterPhase methods, but when the case is RenderResponse phase, he realizes a deadend. The component cannot get the time after render response phase because component itself(the info it has collected so far) is already rendered in the render response phase. So what should he do to measure how long render response phase takes and render it to the page correctly?
One solution is a bit tricky, the component renders something special (buffered by JSF) that will be replaced at after render response phase. When jsf calls afterPhase method of the render response phaselistener, Roni takes the scene; first gets the time then replaces the measured time with the special token in the response buffer using string tricks. He actually does filtering in the render response phase listener. When the response reaches the client, whole info will be correctly displayed.