• 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

What phase is it?

 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can you find out the current phase, from within a managed bean method (for instance)? Why? I'm trying to hack something because JSF has got me
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The below link helps you in order to set up a phase listener for your JSF application.

http://www.jroller.com/page/cschalk?entry=getting_familiar_with_the_jsf

Put some debug (System.out.println or (SOP in short))statements in your managed bean method and then in your console you should be able to see at what phase are your methods being called.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the tip. I know about PhaseListeners, but I was hoping that I wouldn't have to write one just to find out the current phase -- I was hoping this was already exposed more directly in the API. In the end, I realized that all my bean method cared about was whether or not it was being called when rendering a response, and the following is sufficient for that:

FacesContext context = FacesContext.getCurrentInstance();
boolean renderResponse = context.getRenderResponse();

Perhaps my problem could be solved in a cleaner way, so allow me to describe it:

I have an ordinary web page: the top half lets you insert, edit or delete records and the bottom half has a MyFace's DataTable that shows the results of selecting certain summary information from the database. The bean backing this table is request-scoped and its data method used to go to the database the first time it was called:

The trouble with this is that when you submit from this page, before the insert/update/delete action is done, the view is restored which means that my getResults method is called! So my results are a snapshot of the db's state *before* the database action. My solution was to make this method even lazier -- don't try to find any data until the response phase:

This works but I wish it were cleaner. I'm not sure what I want, but since my table has no input fields in it, I wish the backing bean was not created until the response phase. Hmmm.... could this be because my results table is inside the HTML FORM tags? I'll have to play with this a bit more...
[ May 04, 2006: Message edited by: Jeff Albertson ]
 
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming the backing bean is the same, for both the top and the bottom half of the page, probably this might work.
Tie the action listener event of the top half-page in order to initialize an instance variable that can be checked in your getResults()method. Since action listeners happen at phase 5, you should be pretty much lazily loaded.

Please let us know if this worked for you.
Sample code is as below.


[ May 04, 2006: Message edited by: g madhava ]
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if that approach is any better than what I suggested. The trouble with it is that the table needs to be rendered whenever this page is displayed, not just after carrying out a insert/save/delete. For example, there are lots of other pages that are linked to this page, and I don't know if its a good idea to require those pages to know about setting that flag. I'd like my backing bean to look after itself...

(BTW, moving this table out of the scope of the FORM tags didn't change anything.)
 
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>>> This works but I wish it were cleaner.

I was just giving an alternate solution that doesn't deal with the FacesContext. and is much cleaner.(atleast in my opinion).



I didn't get your point overhere,


table needs to be rendered whenever this page is displayed, not just after carrying out a insert/save/delete.


The table will always be rendered, but the data will be loaded pretty lazily. I thought that was the requirement.
May be I was missing something ?

For example, there are lots of other pages that are linked to this page, and I don't know if its a good idea to require those pages to know about setting that flag. I'd like my backing bean to look after itself...



Yes, if all the pages need this particular lazy loading of the data, then you should be fine with the above solution. But in case if you want it to be customized for each different page, then you might need to have some more code for conditional checking using the viewId of the request page.


YMMV...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using JSF 2.0 or later just use:

 
Alas, poor Yorick, he knew this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic