我有三个托管bean:一个会话范围的(S)和两个视图范围的(A、B)。 我想在S和B中使用A的功能。 但是问题在于无法在会话范围的bean中注入视图范围的bean。
The scope of the object referenced by expression #{a}, view, is shorter than the referring managed beans (s) scope of session
我不想重复 A 的功能。有什么想法吗?
我有三个托管bean:一个会话范围的(S)和两个视图范围的(A、B)。 我想在S和B中使用A的功能。 但是问题在于无法在会话范围的bean中注入视图范围的bean。
The scope of the object referenced by expression #{a}, view, is shorter than the referring managed beans (s) scope of session
<h:commandXxx ... action="#{sessionScopedBean.doSomething(viewScopedBean)}" />
但这也是一种设计问题。你需要确保选择正确的作用域来容纳bean所持有的数据/状态。参见如何选择正确的bean作用域?
我想通了。JSF 改变了注入的方式。请看下面正确的方法:
@Named(value = "propertyFEnd")
@ViewScoped
public class PropertyFEnd implements Serializable {
@Inject @ManagedProperty("#{userFEnd}")
private UserFEnd userfend;
**** plus getter/setter for userfend ***
**** your code ****
}
不要在顶部使用@ManagedBean
!!!注意:UserFEnd
是一个会话bean。
希望这可以帮助到您。