CDI 对话和 primefaces 向导组件
我刚刚意识到我的向导组件忘记了过去的步骤,因为我正在使用 @RequestScoped 向导支持 bean。使用 @SessionScoped 可以工作,但很难看。 因此,我尝试使用 @ConversationScoped 让它工作,但不得不意识到一些奇怪的效果。 (也许出于 J2EE 经验)
给定这种向导支持 bean:
@Named
@RequestScoped
public class EvaluationWizard implements Serializable {
...
@Inject
private Conversation conversation;
@Inject
private Song selectedSong;
...
public void setSelectedSong(final Song song) {
selectedSong = song;
}
public Song getSelectedSong() {
return selectedSong;
}
public void onDialogOpen(final ActionEvent actionEvent) {
conversation.begin();
}
public void onDialogClose(final CloseEvent closeEvent) {
conversation.end();
}
...
}
我的 Song 对象如下所示:
@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;
}
}
该向导包含几个步骤来进行设置。 selectedSong 属性是列表中的一项,代表当前选定的歌曲。 这一选择保存在“EvaluationWizard”支持 bean 中,并且我的调试确认情况确实如此 - 但这只是一个向导步骤的情况。
对此的任何帮助将非常感激。
问候,马塞尔。
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;
}
public 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Primefaces 向导组件将无法与 RequestScoped beans 一起使用,您是对的。您必须使用
@SessionScoped
或@ViewScoped
。我个人喜欢使用 ViewScoped,因为该 bean 将在您导航到页面时创建,并在您离开页面时消失。这为您提供了持久 Bean 的好处,而不会扰乱会话。
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.
是的,@RequestScoped 不起作用。直到今天我们还使用@SessionScoped。今天我了解到,使用 @ViewAccessScoped 更好,因为与 @SessionScoped 相比,您可以获得窗口隔离。在我们的应用程序中,我们遇到了很多由@SessionScoped 引起的错误。我刚刚用 @ViewAccessScoped 替换了它,并在 10 分钟内解决了 17 个不同的问题。
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.