One million dollar JSF Puzzle

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.

5 Responses to One million dollar JSF Puzzle

  1. Petrica says:

    aspectwerkz/aspectj rocks for this type of tasks.. just put an aspect around the component and you can easy measure how much time it took to render it.

  2. cm says:

    Why not use ajax for this kind of task?
    in an onload event you ask the server for the time.
    Of course you have to store the time somewhere in the session..🙂

  3. Cagatay says:

    Dont think so, result of using ajax, every user of the library must change the onLoad event.

  4. cm says:

    Cagatay,

    With Javascript you can add as many onload events as you like. The user doesn’t note it at all (you can do it in your renderer for instance). The only thing you need is JS support on the client. But this shouldn’t be a problem🙂

    Here is how you do it with standard JS. If you need to support IE and other weired browsers google for it.. There are some generic solutions around..

    window.addEventListener(‘load’, loadMyData, false);

    where loadMyData is your function..

  5. Cagatay says:

    Yes, right that will solve the problem at the client side. So including yours there are two solutions to the puzzle now:)

%d bloggers like this: