aspose file tools*
The moose likes JSF and the fly likes control the running order of different back bean functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "control the running order of different back bean functions" Watch "control the running order of different back bean functions" New topic
Author

control the running order of different back bean functions

reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
I'm using JSF 1.1 to create a web app.
In a page, I have a link, when you click it, it will switch between English and French, and so does the rest of content on the page.

But I found a table's header is switching one step behind for language change, that is, when I click French, the table header is still showing English. When I click English, the table header shows French. If I refresh the page, the table header shows correctly then. (Table header is loaded from DB with both English and French column)

The code for the link is this:



I have a java class, say TableSummary.java as the back bean for the table and other content.
So how should I control that localeChanger.onChooseLocale is always running first before tableSummary back bean class get executed? Since I need set the session value for locale in LocaleChanger class first, then I will need get value in TableSummary class. Even through the link is written before the table header and content, I found session is set after the table reloaded...

Thanks.


SCJA, SCJP5.0, SCBCD, SCWCD
Mole Moore
Greenhorn

Joined: Apr 03, 2009
Posts: 6
Hello reubin,
I am new to JSF, so please take this with a grain of salt. I am kind of hoping that those more experienced in JSF will let me know of a better way to do this.

I had a need to perform some first-time logic before any code in my backing bean was ran. This seems to be kind of what you are needing to do? Lookup a value from a database and place it in session before some other code is ran?

Assuming that is correct, I used a PhaseListener that gets fired before any processing in my backing bean is done.

Two things are needed to use a PhaseListener, first a class that implement the JSF PhaseListener interface and an entry in faces-config.xml to register your listener with JSF.

Your PhaseListener class:



Register your listener with JSF.

faces-config.xml:


This probably is not the best solution out there, but it does the job very well.

Mark
reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
thanks for the reply.
But for my scenario, my firstTimeLogic() is actually the constructor of my back bean class, which is supposed to be called from JSF container when the page is loaded. So I cannot really instantiate my back bean class inside firstTimeLogic() method...
 
jQuery in Action, 2nd edition
 
subject: control the running order of different back bean functions