GeeCON Prague 2014*
The moose likes JSF and the fly likes JSF Notes on Events Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Notes on Events" Watch "JSF Notes on Events" New topic
Author

JSF Notes on Events

Tom Fulton
Ranch Hand

Joined: Mar 30, 2006
Posts: 95
About a week ago, I asked a question in this forum concerning JSF events, and how to accomplish a particular task. Apart from using Ajax, no one seemed to know how to accomplish a task that I thought would be fairly easy. Being a fairly stubborn individual, I decided to learn everything there was to know about the JSF lifecycle, order of event firing and related topics. Here is what I discovered:

1.The current state of JSF documentation is inadequate. There are large gaps both in the standard documentation (both javadoc and in the specification) as well as published books and articles concerning certain features.

2.There is no substitute for trying out features. Because of the lack of good documentation, the only way to really determine what is happening is to try out and document behavior. This is time-consuming, but in my experience the only thing that really worked.

3.immediate=�true� is the feature that is (so far) the worst understood and is poorly described in the API. One (generally excellent) book says that the attribute �determines whether or not the component�s input should be converted and validated immediately (during the Apply Request Values phase�)�. Not true�based on testing with Phase Events:

a.When immediate=�true� is applied to a command component, it causes the associated ActionListener to execute at the end of the �Apply Request Values� phase of the lifecycle. Then (and this is the part that is not well documented) FacesServlet goes directly to the �Render Response� phase, bypassing validation and model update. This occurs automatically, without any need for the developer to formally code it.

b.When immediate=�true� is applied to an input component such as a radio or text control, the associated ValueChangeListener executes at the end of the �Apply Request Values� phase as well, but only after the form is submitted (common sense). You must add onchange=�submit( )� to the tag if you want the component change itself to submit the form. The developer must code explicitly to render the response from a ValueChangeListener�if this isn�t done, the next phases (validation and model update) occur normally.

c.If you want a component to directly update the appearance of another component, both must have their immediate attribute set to �true� or the behavior is �unspecified��which means it doesn�t work, at least in the RI. And again, the form must be submitted (absent any Ajax processing to do so)

4.More complex actions (such as updating a GUI component from the model during a ValueChangeListener) require a thorough understanding of how to manipulate the event queue, and should not be undertaken lightly.

I am hoping that by publishing these notes I can help another developer avoid the frustrating hell I've experienced over the past week.
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
nice one Tom.

Here is what I used to understand the JSF lifecycle

http://balusc.xs4all.nl/srv/dev-jep-djl.html
[ January 24, 2007: Message edited by: Richard Green ]

MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Tom Fulton
Ranch Hand

Joined: Mar 30, 2006
Posts: 95
Man, if only I'd found that page a week ago! Thanks, I bookmarked it immediately. The one bright spot to fighting through this myself is that I doubt I'll ever forget how it works. :thumb:
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
You may want to bookmark this one too

http://facestrace.sourceforge.net/main/screenshots.html
 
GeeCON Prague 2014
 
subject: JSF Notes on Events