简体   繁体   中英

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

Java 1.7 / JSF 2 / JPA 2 / Hibernate 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.

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);
  2. Show an editing page (supported by another backing bean) to edit a particular item of the listing;
  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.

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. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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