简体   繁体   English

如何使用@ConversationScoped处理多个支持bean?

[英]How to use @ConversationScoped to handle more than one backing bean?

Java 1.7 / JSF 2 / JPA 2 / Hibernate 4 Java 1.7 / JSF 2 / JPA 2 /休眠4

I have read a number of tutorial and posts about @ConversationScoped and in all of them the message is the same: use it when you have many views for one backing bean. 我已经阅读了许多有关@ConversationScoped的教程和文章,并且在所有这些文章中,消息都是相同的:当您对一个后备bean有很多视图时,请使用它。

However, I have a business process scenario where I have to: 但是,我有一个业务流程场景,其中我必须:

  1. Show a number of items in a listing page (supported by a listing backing bean); 在列表页面中显示许多项目(由列表支持Bean支持);
  2. Show an editing page (supported by another backing bean) to edit a particular item of the listing; 显示一个编辑页面(由另一个支持Bean支持)以编辑列表中的特定项目;
  3. After the editing is finnished, go back to the listing page that should show the same previous context. 编辑完成后,请返回应该显示相同先前上下文的列表页面。

The editing page is complex and have many dependencies that do not make sense to be in the listing backing bean, that's why I prefer to have two backing beans working over two different pages, but in one single business context. 编辑页面很复杂,并且具有许多依赖关系,因此在列表支持bean中就没有意义了,这就是为什么我更喜欢让两个支持bean在两个不同的页面上工作,而只是在一个业务环境中。

Can that be achieved? 能做到吗? What are the steps? 步骤是什么?

After some testing, I could make it to work. 经过测试,我可以使其正常工作。 All I had to do was to add the cdi button parameter on my edit button. 我要做的就是在编辑按钮上添加cdi button参数。 In order to make it to work, my edit button had to be something like this: 为了使其正常工作,我的编辑按钮必须是这样的:

<p:commandButton title="Edit"
                 action="#{myMB.nextView}"
                 ajax="false">
    <f:param name="id" value="#{bean.id}"/>
    <f:param name="cid" value="#{myMB.conversation.id}"/>
</p:commandButton>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM