6 Replies Latest reply on Nov 6, 2012 5:40 PM by Tony Herstell

    Two conversations created instead of one with conversation.begin() in @PostConstruct method

    Luca Cavagnoli Newbie

      Before issuing a bug, I'd like someone to try the following, which exposes a weird  behaviour in Weld's conversation management.

       

      All will work fine if you use this bean/page as they are, but if you move the outputText with id 'convout' inside the form, two conversations will be started instead of one!!! The first conversation will be righfully created when the pages is requested the rist time. But another one will be created when you press the 'Increment' button.

       

      (I'm experiencing this with JBoss AS 7.1.1.Final, JBoss Developer Studio 5, with a Java EE Web Project)

       

      ConvTest.java

       

      @Named
      @ConversationScoped
      public class ConvTest implements Serializable {
      
          private static final long serialVersionUID = 2866431447137331469L;
      
          @Inject
          private Conversation conversation;
      
          private int counter;
      
          @PostConstruct
          public void postCon() {
              if (conversation.isTransient())
                  conversation.begin();
          }
      
          public void increment() {
              counter++;
          }
      
          public Conversation getConversation() {
              return conversation;
          }
      
          public int getCounter() {
              return counter;
          }
      
      }
      

       

      index.xhtml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html">
      <h:head>
      </h:head>
      <h:body>
      
          <!-- Moving this outputText inside the form causes the side effect -->
          <h:outputText value="#{convTest.conversation}" id="convout"/>
      
          <h:form>
              <h:commandButton value="Increment" action="#{convTest.increment}" />        
          </h:form>
      
          <h:outputText value="#{convTest.counter}" />
      
      </h:body>
      </html>