I have a JSF facelets page that displays a table of data depending on which page they are viewing. When I display page 1, I call the view()
action method to get the data from the database for both pages and store it as a private member field of the bean (two arrays). I also call conversation.start()
on the injected conversation instance in the view()
method.
When the user clicks the "next" button (h:commandButton
) to go to page 2, I am executing a next()
method to update the backing bean to point to array 2 so it will print out its contents. The problem is, array 2 no longer exists. I don't know why I am losing conversation scope. Any ideas?
//tells the object which page we are on, and thus what data to display.
private int part = 1;
// These arrays are filled with data but conversation scope doesn't
// keep them on the next postback.
private int[] part1 = new int[15], part2 = new int[15];
You should paste some more code so we can help you better. From what you say i cannot see where you called the method for ending the conversation(You need that too when working with conversation scope).
I will paste here a little example that i think will help you understand how conversation scope works:
This is the start page of a wizard(Conversation scope is great for wizards)
This is the second page of the wizard
And this is the page where the scope ends
Here the @ConversationScoped backing bean that starts and ends the conversation
I think this example is very simple and can help you understand how it works. Ask if you don't understand something
NOTE:
I think but i am not sure at 100% but ConversationScope only works if the backing bean is a CDI bean. This mean uses the annotation @Named. Better double check that.