JSF - Bean注入麻烦

mar*_*zzz 2 java jsf facelets postconstruct jsf-2

正如用户之前在另一个问题中建议的那样,我需要在另一个bean中注入一个bean.

所以,我做以下事情:

@ManagedBean
@RequestScoped
public class Articles {
    private String selectedMenu;

    @ManagedProperty(value="#{user}")
    private UserManager user;

    @PostConstruct
    public void init() {
        if(selectedMenu==null || selectedMenu.trim().isEmpty()) {
            this.selectedMenu="0";
        }
    }

    // now here i should access to user.methods

    // getter and setter
}
Run Code Online (Sandbox Code Playgroud)

实际上,我无法访问UserManager数据.我收到这些错误:

BROWSER malformedXML: INVALID_STATE_ERR: Dom Exception 11

服务器日志 30-nov-2010 15.36.58 javax.faces.component.UIViewRoot$ViewMap put AVVERTENZA: Setting non-serializable attribute value into ViewMap: (key: profileSelector, value class: model.ProfileSelector) 30-nov-2010 15.36.59 com.sun.faces.mgbean.BeanManager preProcessBean GRAVE: JSF will be unable to create managed bean articles when it is requested. The following problems where found: - Property user for managed bean articles does not exist. Check that appropriate getter and/or setter methods exist. 30-nov-2010 15.36.59 com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback visit GRAVE: com.sun.faces.mgbean.ManagedBeanCreationException: Unable to create managed bean articles. The following problems were found: - Property user for managed bean articles does not exist. Check that appropriate getter and/or setter methods exist.

如果我评论,@ManagedProperty(value="#{user}")private UserManager user;不是我没有看到任何错误.这就是问题所在.我错了什么?

干杯

Bal*_*usC 5

malformedXML:INVALID_STATE_ERR:Dom例外11

此XML错误表示视图中的错误(XHTML),而不是bean中的错误.我不明白为什么会出现这个错误,但很可能你是一个非常复杂的组件树rendered,它有几个属性,其中一个属性取决于在user客户端的XML树中导致错误状态的属性.

至于服务器日志:

AVVERTENZA:将不可序列化的属性值设置为ViewMap :(键:profileSelector,值类:model.ProfileSelector)

这不一定有害,但要修复它,你需要让类实现java.io.Serializable.

public class ProfileSelector implements Serializable {}
Run Code Online (Sandbox Code Playgroud)

这样,服务器将能够通过网络传输实例和/或在必要时(当服务器重新启动或放置在服务器群集中时)将实例存储在硬盘上而不是存储在内存中.


30-nov-2010 15.36.59 com.sun.faces.mgbean.BeanManager preProcessBean GRAVE:JSF将无法在请求时创建托管bean文章.找到以下问题: - 托管bean文章的属性用户不存在.检查是否存在适当的getter和/或setter方法.

这也是自我解释.确保user使用名称为托管bean 的属性提供正确的getter/setter方法articles.

@ManagedBean
@RequestScoped
public class Articles {

    @ManagedProperty(value="#{user}")
    private UserManager user;

    public UserManager getUser() {
        return user;
    }

    public void setUser(UserManager user) {
        this.user = user;
    }

}
Run Code Online (Sandbox Code Playgroud)

如有必要,您可以让IDE自动生成它们.在Eclipse中,检查右键单击上下文菜单(Alt + Shift + S)中的Source部分.


30-nov-2010 15.36.59 com.sun.faces.context.PartialViewContextImpl $ PhaseAwareVisitCallback访问GRAVE:com.sun.faces.mgbean.ManagedBeanCreationException:无法创建托管bean文章.发现以下问题: - 托管bean文章的属性用户不存在.检查是否存在适当的getter和/或setter方法.

这有同样的问题原因.