I have a jsf 1.2 application where I need to show a page (jsp) which has a backing bean. Most examples I see for help show a blank jsp for user ot edit. In my case I need to get some Data from DB before jsp loads, how to accomplish this?
I tried @postconstruct on a backing bean method but if I share this bean with multiple JSPs it is initializing the info for all pages, I need different data for different page and each page should read some data from db before displaying in JSP.
I am coming from Struts background where I would invoke the URL for the Action which will call have Business logic to get data and then I would direct to JSP. For accomplishign this with JSF it seems not pretty straightforward.
The page (view) should have its own request/view scoped backing bean which is not shared elsewhere. That should fix your “problem” (which is actually just a design matter). Do not use a single session scoped bean for multiple views. That’s wrong use of the session scope.
JSF and Struts are very different. JSF is a component based MVC framework while Struts is an action based MVC framework. You should not design JSF backing bean classes while having Struts action classes in mind. Going through some decent JSF tutorials should put you on the right track. For an overview, see also the bottom of our JSF wiki page.
Please note that JSF 1.2 is completely outdated. JSF 2.0 has been released over 2 years ago already. If this is a new application or just hobbying, I recommend to forget JSF 1.2 and continue with JSF 2.0.