Weld + JSF 2.0 @ConversationScoped no mantiene el estado

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 ?

Muchas gracias por sus respuestas !

preguntado el 01 de febrero de 12 a las 22:02

I'm not sure what you mean by "doesn't keep state"? What is the result you are expecting and what is happening? -

When I click the button, I'm hopping that the number conversationTest.counter is incremented, but it's not. -

1 Respuestas

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.

Respondido 29 Feb 12, 11:02

Thank you for your answer ! I will try to use h:commandButton and let you know about the result ;) - Zarkus13

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.