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中,我的调试确认是这种情况-但这仅是一个向导步骤的情况。 对此的任何帮助将是非常感谢的。 问候,马塞尔。     
已邀请:
        Primefaces向导组件不适用于您正确的RequestScoped Bean。您必须使用
@SessionScoped
@ViewScoped
。 我个人喜欢使用ViewScoped,因为将在您导航到该页面时创建该bean,而在离开该页面时将使其消失。这为您提供了持久化bean的好处,而不会使会话混乱。     
        是的@RequestScoped无法正常工作。直到今天,我们还使用了@SessionScoped。今天,我了解到最好使用@ViewAccessScoped,因为与@SessionScoped相比,您可以获得窗口隔离。在我们的应用程序中,我们遇到了许多由@SessionScoped引起的错误。我只用@ViewAccessScoped替换了它,并在10分钟内用它解决了17张不同的票。     

要回复问题请先登录注册