1

I'm trying to use CDI conversation scope and I have some doubts: - Do I need to propagate cdi id when use ajax request?

For example:

    <p:spinner value='#' min="1" max="99" styleClass="spinerqtde" title="Quantidade" stepFactor="1" maxlength="2">
<f:param name="cid" value="#{carrinho.conversation.id}"></f:param>
<p:ajax update="@form" listener='#{carrinho.lstSpinerProduto}' process="@this" />
</p:spinner>

Because when I don't, I realized that the method "@postConstruct" is initialized again, and is created a new CID.

ManagedBean code:

@Named("carrinho")

@ConversationScoped
public class CCarrinho implements Serializable
{
.
.
.
 @Inject
    private Conversation conversation;
.
.
.
 @PostConstruct
    public void inicializar()
    {
    if (getConversation().isTransient())
    {
      getConversation().begin();

    }
    }

Thanks. Bye!

Victor Bello
  • 493
  • 1
  • 8
  • 23

1 Answers1

1

The id of the current conversation is kept in the current view and when you perform a post back (the ajax request is also a postback) the conversation id is there so there is no need for you to provide it.

Adrian Mitev
  • 4,722
  • 3
  • 31
  • 53
  • Could you clarify this to me? If you don`t need to provide the CID, why the OP say this?: _Because when I don't, I realized that the method "@postConstruct" is initialized again, and is created a new CID_. – Javier Haro Oct 19 '15 at 10:14
  • But, why when you don't provide the CID manually via f:param conversation scope is restarted? This is my doubt. – Javier Haro Oct 19 '15 at 11:44
  • f:param nested in which component? – Adrian Mitev Oct 19 '15 at 12:26
  • f:param carrying the CID nested in the component performing the ajax request, an h:commandButton for intance. – Javier Haro Oct 19 '15 at 12:30
  • This should work out of the box without the need to provide f:param with the conversation id. If it doesn't this might be a bug. – Adrian Mitev Oct 19 '15 at 12:36
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92749/discussion-between-adrian-mitev-and-lametaweb). – Adrian Mitev Oct 19 '15 at 15:35