0

Java 1.7 / JSF 2 / JPA 2 / PrimeFaces 6.1

I'm refactoring my application to use @ConversationScoped. I have a backing bean that allows the user to select a number of entities after providing some search arguments. For each row in the resulting listing I have a Edit button that navigates to another view.

Everything was working until a annotated the backing bean with @ConversationScoped. After that, everytime the user clicks any of edit buttons, the search page simply reloads and no navigation happens.

The edit method bound to the edit button is not called anymore.

Any ideas?

AlexSC
  • 1,823
  • 3
  • 28
  • 54
  • Debug all this: https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value. And **always** (try to) create a [mcve] – Kukeltje Apr 26 '18 at 17:20

2 Answers2

0

Did you mark the Conversation as persistent via Conversation#begin()?

A CDI Conversation by default is 'transient', that means it behaves the same like a @RequestScoped bean.

If you have your backing bean then simply inject the Conversation into it:

private @Inject Conversation conversation;

Then call conversation.begin() in your action which should open a Conversation.

Be careful and note that you also need to explicitly end() your Conversation!

A much easier way to deal with this in your code might be to leverage the Apache DeltaSpike @ViewAccessScoped. This is kind of an 'auto-conversation'. The contextual instance will be kept active as long as you access it. Once you navigate away and don't touch it anymore it will get destroyed.

This btw also deals with multiple browser tabs. We even have a separate scope for it: @WindowScoped. This gives you separate instances per browser tab! Might also work well for your usecase.

struberg
  • 730
  • 5
  • 12
0

I was not adding the cdi button parameter. In order to fix the problem my 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>

Notice the cid parameter, it wasn't there when I had the problem I described.

AlexSC
  • 1,823
  • 3
  • 28
  • 54