GlassFish4,JSF2.2,JavaEE7:
ManagedBean controllerBean
被注入ManagedBean pb
(for progressBar):
@ManagedBean
@ViewScoped
public class Pb implements Serializable{
public Pb() {
}
@ManagedProperty(value = "#{controllerBean}")
ControllerBean controllerBean;
public void setControllerBean(ControllerBean controllerBean) {
this.controllerBean = controllerBean;
}
public Integer getProgress() {
return controllerBean.getNumberOfComputations();
}
}
- >方法getProgress()
以numberOfcomputations
为增量返回不同的值作为整数controllerBean
。
但是当我使用@Inject
代替@ManagedProperty
时:
@ManagedBean
@ViewScoped
public class Pb implements Serializable{
public Pb() {
}
@Inject
@ControllerBean controllerBean;
public Integer getProgress() {
return controllerBean.getNumberOfComputations();
}
}
然后getProgress()
一直返回0,这是controllerBean中numberOfComputations
的初始状态,即使此整数在controllerBean
中快速增加。
发生了什么事?
答案 0 :(得分:1)
您应该用CDI替换所有JSF注释:
@ManagedBean => @Named
@javax.faces.bean.ViewScoped => @javax.faces.view.ViewScoped
@ManagedProperty => @Inject