• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Events on lifecycle phases

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's possible to call a method of backingbeans, triggered by arbitrary events on lifecycle of request? i.e. I want to call one method on my backingbean when restore view phase has been done.

My intention is to update components state, behaviour or fashion (in my backingbeans), on the startup of my pages, depending on model state. i.e. Set some css style on certain components if business rules require it when use open a page.

Currently, I'm picking these behaviours in set and get methods of my backingbeans... Some help?

best regards,
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In JSF, what you are attempting to do (I believe) is a Phase Listener. Although it's possible to perform the work in a backing bean by implementing the listener interface, it's more commonly done in a separate class that implements the interface. Phase Listeners can be invoked before or after any phase...in your case, you would want to invoke it after the RESTORE_VIEW phase.

That being said, I suspect that your application is attempting to do something that may be easier without the phase listener. You were referring to "updating the components state, behavior or fashion (in my backingbeans) on the startup of my pages". A lot of that can be done by just using the lifecycle in the way in which it was designed. For an excellent description of the work that occurs automatically in the different lifecycle phases, see JavaServer Faces: The Complete Reference. Although the index is rather poor, the first chapters are a very good tutorial on this topic.

As an example (and off the top of my head...there might be a different/better way to do this): you can include markup using the <f:verbatim> tag, which can be rendered or not depending on the state of backing bean properties. This would give you the ability to specify different CSS for different runtime conditions. And often, there is no need to directly interact with the component tree and the values contained therein...again, depending on your application.
 
Victor Dolirio
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tom, thanks, this was just what I wanna hear. I hate to do complex actions to accomplish simple requirments. I'll be more thankful if help me to understand what you say with an example.

I have a entity named "Event". This entity have a datetime to the begin and other to the end of the event. If user open the view page of this event just in the time this event is happening, I need to put a style in the label of the caption of the event, as follows:

CSS style:


code snippet for the Page:


What I would do to apply the css class if event is happening just in the time the user open this page? (don't worry with logic of dates, I just wanna know what to do with JSF).

Best regards,
 
author
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Victor,

This can be accomplished with very little effort. Suppose your event object has a boolean property happening, you could write the following code:

That's all.

Best regards,
Bart
 
Tom Fulton
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bart beat me to it! Exactly what I was going to suggest...use the "style" attribute (common to all UI component tags), and have that point at an EL expression that returns the appropriate style.

The property Bart was referring to would simply determine if the current time was within the range of "begin" to "end". If so, it returns "true"...if not, it returns "false". The style would therefore dynamically change according to runtime conditions.
 
Victor Dolirio
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice! It's exactly what I need! Simple and agile.

Thanks all you!
 
reply
    Bookmark Topic Watch Topic
  • New Topic