Weld + JSF 2.0 @ConversationScoped doesn't keep state

1k Views Asked by At

I'm trying to use CDI's implementation Weld, on a JBoss AS 7, and within a JSF 2. 0 application.

The fact is that my @ConversationSconed @Named bean doesn't seem to keep his state when I begin the conversation.

In ordre to see that, I am just using a counter, that I increment each time I click on a command button, using Primefaces and ajax.

The beans.xml is present in the classpath (META-INF, WEB-INF ...), and I just wanna precise that with a @SessionScoped bean or a @ManagedBean @ViewScoped, it works very well !

But I prefere to use @ConversationScoped and stay with a @Named bean, rather than using @ManagedBean.

Maybe I have to do additionaly configuration for JBoss AS 7 or in the web.xml, I don't know ...

Here is my @ConversationScoped bean :

@Named
@ConversationScoped
public class ConversationTest implements Serializable {
    private int counter;

    @Inject
    private Conversation conversation;

    public void startConversation() {
        System.out.println(counter);

        counter++;

        if(conversation.isTransient())
            conversation.begin();
    }

    public void stopConversation() {
        if (!conversation.isTransient())
            conversation.end();
    }

    public int getCounter() {
        return counter;
    }

    public void setCounter(int counter) {
        this.counter = counter;
    }
}

And here is the content of my xhtml page :

    <h:form prependId="false">
        <h:panelGroup id="tests">
            <h:outputText value="#{conversationTest.counter}" /> <br/>
            <h:outputText value="Test : #{conversationTest.testHello}" /> <br/><br/>
        </h:panelGroup>

        <p:commandButton
                value="Start !"
                actionListener="#{conversationTest.startConversation}"
                update="tests" />
        <br/>

        <p:commandButton
                value="Stop !"
                actionListener="#{conversationTest.stopConversation}"
                update="tests" />
    </h:form>

What am I doing wrong ? Am I forgetting something ?

Thank you very much for your answers !

1

There are 1 best solutions below

1
On

Have you tried using the standard h:commandButton instead of the PrimeFaces variety? If the PrimeFaces one is using AJAX (which as I recall it is) you may need to send along the conversation id as a param.