CDI conversation and primefaces wizard component
I just realized that my wizard component forgets the steps that lay in the past as I'm using a @RequestScoped wizard backing bean. Using @SessionScoped will work but is ugly. Thus I tried to get it working using @ConversationScoped but had to realize some strange effect. (maybe out of J2EE experience)
Given this kind of wizard backing bean:
@Named
@RequestScoped
public class EvaluationWizard implements Serializable {
...
@Inject
private Conversation conversation;
@Inject
private Song selectedSong;
...
public void setSelectedSong(final Song song) {
selectedSong = song;
}
pub开发者_JAVA技巧lic Song getSelectedSong() {
return selectedSong;
}
public void onDialogOpen(final ActionEvent actionEvent) {
conversation.begin();
}
public void onDialogClose(final CloseEvent closeEvent) {
conversation.end();
}
...
}
My Song object looks like this:
@Named
@ConversationScoped
public class Song extends SelectItem implements Serializable {
private String title;
public void setTitle(final String title) {
this.title = title;
}
@Override
public String toString() {
return title;
}
}
The wizard contains several steps in order to set things up. The selectedSong property is an item of a list and represents the currently selected song. This selection is saved in the "EvaluationWizard" backing bean and my debugging confirms that this is the case - but it's only the case for one wizard step.
Any help on that would be very appreciative.
Greetings, Marcel.
The Primefaces wizard component will not work with RequestScoped beans you are correct. You must either use @SessionScoped
or @ViewScoped
.
I personally like using ViewScoped as the bean will be created when you navigate to the page and will die when you leave the page. This gives you the benefit of a persisted bean without cluttering up the session.
Yes @RequestScoped won't work. Until today we also used @SessionScoped. Today I learned that it's better to use @ViewAccessScoped because you get window isolation compared to @SessionScoped. In our App we got a lot of bugs caused by @SessionScoped. I just replaced it with @ViewAccessScoped and I solved 17 different tickets in 10 minutes with it.
精彩评论