我想在JBoss AS 7和JSF 2.0应用程序中使用CDI的实现Weld。Weld + JSF 2.0 @ConversationScoped不保持状态
事实是,当我开始对话时,我的@ConversationSconed @Named bean似乎没有保持他的状态。
在ordre中看到这一点,我只是使用一个计数器,每次点击命令按钮时使用Primefaces和ajax就会增加计数器。
beans.xml存在于类路径(META-INF,WEB-INF ...)中,我只是想用@SessionScoped bean或@ManagedBean @ViewScoped精确地说,它工作得很好!
但我优先使用@ConversationScoped并保留@Named bean,而不是使用@ManagedBean。
也许我需要做的JBoss的additionaly配置7或在web.xml中,我不知道......
这里是我的@ConversationScoped豆:
@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;
}
}
这里是我的xhtml页面的内容:
<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>
我在做什么错了?我忘记了什么吗?
非常感谢您的回答!
我不确定你的意思是“不保持状态”?你期望的结果是什么?发生了什么? – 2012-02-19 22:45:27
当我点击这个按钮时,我跳跃的是conversationTest.counter的数字增加,但事实并非如此。 – Zarkus13 2012-03-01 17:26:33