Firstly, some background on my java web application development experience. I have previously developed a web application using Visual Web JSF (the IDE is NetBeans 6.5, and GlassFish V2 as the application server) - this is my only experience in java web application development so far.
I'm now beginning to venture into RichFaces. I encounter a problem in some of the backing beans of my RichFaces pages, where I need to retrieve data from database and then use these data to populate the values of the components (mostly output text fields and comboboxes) when the page is rendered for the first time, but the datasource is not available and hence, I am not able to do what I wanted to do.
This is my scenario:
In the first page user selects a command link, in the backing bean of page1 the action of the command link will assign a value to a session variable and then navigates to the second page.
In the second page, I will check if the session variable is not null in page2 backing bean, if true then I will use datasource to connect to database to retrieve data, and then use the data to populate the fields in second page. But I do not have method like prerender( ) where the datasource is already initialised and usable.
Previously in Visual Web JSF Page I can do this in the backing bean's prerender() method, but using RichFaces I don't know where this prerender() method (or something similar) going to come from.
I spent many days trying to search for information in the internet, found Apache Shale framework but it has recently retired, so I decided not to use it first unless I have no other choice.
Other information I found, such as on the JBoss Seam and MyFaces Orchestra, are just too complicated and confusing for my level of experience. I only wanted something that can do init() and prerender() in my backing bean.
Appreciate if anyone can advise me how it can be done (including maybe ask me to forget about Visual Web JSF way of development but please show me the "right" way how a web application employing RichFaces components should be developed), or direct me to a relevant tutorial website.
Define a session backing bean for the second page. In the command method get this bean from the FacesContext and fill it with data. Then just render the page having your elements' values set to the same bean. Don't forget to declare keepAlive element with your backing bean as parameter for richfaces ajax operations.
Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
Wen Ping Fong
Joined: Oct 31, 2009
Thanks for your reply, and sorry for the late, I was away.
I will try the your suggestion. Will post the result or maybe ask further question after I try. I haven't used FacesContext to get a bean, nor use the keepAlive element before, so might post my result a bit later because I need to learn those things first.