[英]@ViewScoped @ManagedBean destroyed when using <h:link includeViewParams=“true”>
I'm using Mojarra 2.2.12. 我正在使用Mojarra 2.2.12。 I have a case where a
@ViewScoped
@ManagedBean
is immediately destroyed on page load, although the view is not ended. 我有一种情况,尽管视图未结束,但
@ViewScoped
@ManagedBean
在页面加载时立即被销毁。 The problem is reproducible with solely the below in <h:body>
: 仅使用
<h:body>
的以下内容即可重现该问题:
<h:outputText value="#{testBean.value}" />
<h:link outcome="other" includeViewParams="true">link</h:link>
The other
must refer to a different view and not the same view. other
必须引用不同的视图,而不是相同的视图。 There's no <f:viewParam>
necessary to reproduce the problem. 无需
<f:viewParam>
即可重现此问题。
And the below bean: 和下面的bean:
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
public class TestBean implements Serializable {
@PostConstruct
public void init() {
System.out.println("@PostConstruct on " + this);
}
@PreDestroy
public void clear() {
System.out.println("@PreDestroy on " + this);
}
public String getValue() {
return "test";
}
}
If we remove includeViewParams="true"
attribute, then the bean is not immediately destroyed.Why does includeViewParams="true"
cause this behavior? 如果删除
includeViewParams="true"
属性,则不会立即销毁该bean。 includeViewParams="true"
会导致此行为?
Add this dependency to pom.xml, I was passed it. 将此依赖项添加到pom.xml,我通过了它。
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.