焊接+ JSF 2.0 @ConversationScoped 不保留状态
我正在尝试在 JBoss AS 7 上和 JSF 2.0 应用程序中使用 CDI 的实现 Weld。
事实是,当我开始对话时,我的 @ConversationSconed @Named bean 似乎没有保持他的状态。
为了看到这一点,我只是使用一个计数器,每次单击命令按钮时我都会使用 Primefaces 和 ajax 递增该计数器。
beans.xml 存在于类路径(META-INF、WEB-INF ...)中,我只想精确地说,使用 @SessionScoped bean 或 @ManagedBean @ViewScoped,它工作得非常好!
但我更喜欢使用 @ConversationScoped 并保留 @Named bean,而不是使用 @ManagedBean。
也许我必须为 JBoss AS 7 或 web.xml 进行额外的配置,我不知道...
这是我的 @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;
}
}
这是我的 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>
我做错了什么?我是不是忘记了什么?
非常感谢您的回答!
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 !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用标准 h:commandButton 而不是 PrimeFaces 品种?如果 PrimeFaces 使用 AJAX(我记得是这样),您可能需要将对话 id 作为参数发送。
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.