If I am navigating from page one to page two, When I click on Page one's submit button, control goes to the managed bean written corresponding to page one, I want to fetch some result from database and show them to page two, I fetched the data from the data base . i want to show the values in another web page . for this i have initialized bean2 from the bean1 method and set all the values .
when i am going to second page the value is not displaying in the page .
t dont know this is the proper way to do it or not .
please hel[p me .
1. You can keep bean1, save the value in bean1 as a property and then have page2 reference bean1's property. There's no law that says that each page can have exactly one and only 1 backing bean or that each page must have a distinct backing bean; share beans if it works better for you.
2. You can inject bean2 into bean1 as a Managed Property and make bean1 inject the database value into bean2 using a bean2 property set method. This is generally best done in the action method that causes navigation to bean2.
In either of the above cases, it's important to pay attention to bean scope. Whichever way you do it requires session scope for the bean that's holding the database values referenced by page2, since any shorter-lived scope (View Scope, Request Scope) will destroy the bean and create a new, uninitialized bean for the second page.
An IDE is no substitute for an Intelligent Developer.
Joined: May 12, 2012
Thanks a lot sir.
I have a question , cant it possible by direct setting the values in the bean2 .
I have tried the same its giving the proper result .
Can i know the reason if its not possible .
i will try the solution given by you and reply .
The first thing you did wrong was you wrote your own login code. Stay around me for very long and you'll quickly learn I'm very stridently against that. The reason for that is because I've never actually seen a user-created security system that was very secure. J2EE has a built-in security system, and most webapps should be using it, not supplying their own.
The second thing you did wrong was that you didn't use the "Code" button on the JavaRanch message editor. The Code tags that this button creates can be used to wrap code, XML, and other preformatted text and present them in a way that's much more readable than regular message text - and doesn't lose all your formatting.
Because your sample was large and not well-formatted, I couldn't read all the details, but you do not appear to be using the JSF injection mechanism. I do recommend you get a good book on JSF and read what it has to say about Managed Properties.