【问题标题】:CDI conversation and primefaces wizard componentCDI 对话和 primefaces 向导组件
【发布时间】:2011-06-14 15:29:32
【问题描述】:

我刚刚意识到我的向导组件忘记了过去的步骤,因为我正在使用 @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 cdi wizard


    【解决方案1】:

    Primefaces 向导组件将无法与 RequestScoped bean 一起使用,您是对的。您必须使用@SessionScoped@ViewScoped

    我个人喜欢使用 ViewScoped,因为 bean 会在您导航到页面时创建,而在您离开页面时会消失。这为您提供了持久 bean 的好处,而不会弄乱会话。

    【讨论】:

    • 谢谢 - 我希望只有一个富客户端 ajax-only 页面不会发生进一步的位置更改。默认的 CDI 实现不提供 ManagedBean 方法附带的 ViewScope。所以我决定看看 Seam 3 及其“Faces”模块,它使用 ViewScoped 扩展了 CDI。这样做后,我根据请求从 RequestScoped 更改为 ViewScoped,但现在向导状态在加载后保持不变。 (感觉像 SessionScoped)对话正确开始和停止,但 ConversationScoped bean 始终保持不变。
    【解决方案2】:

    是的,@RequestScoped 不起作用。直到今天我们还使用了@SessionScoped。今天我了解到使用@ViewAccessScoped 更好,因为与@SessionScoped 相比,您可以获得窗口隔离。在我们的应用程序中,我们遇到了很多由@SessionScoped 引起的错误。我刚刚将其替换为 @ViewAccessScoped,并在 10 分钟内解决了 17 张不同的票证。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-01
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-03
      相关资源
      最近更新 更多