简体   繁体   English

永远不会在ManagedBean上调用@PostConstruct方法init()

[英]@PostConstruct method init() is never invoked on a ManagedBean

I'm still a beginner at JSF programming and I'm trying to do a little example to understand how it works. 我仍然是JSF编程的初学者,我正在尝试做一些例子来了解它的工作原理。 I'm facing the problem where the @PostConstruct method of a managed bean is never invoked (the instanciations in it are never made, and the println in it doesn't show a thing) I tried all sorts of managed beans (Session, Request...), but there is always the same problem ! 我遇到的问题是,永远不会调用托管bean的@PostConstruct方法(永远不会执行实例化,并且其中的println不会显示任何内容),我尝试了各种托管bean(会话,请求...),但始终存在相同的问题!

My managed bean : 我的托管bean:

@ManagedBean(name = "helloWorldMBean")
@SessionScoped
public class HelloWorldMBean implements Serializable {

private static final long serialVersionUID = 1L;
private PortletRequest request;
private String nom;
private String prenom;
private String complement;
private BigDecimal age;
private String year;

/* getters and setters */

@PostConstruct
public void init() {
    System.out.println("Hi !");
    if (request == null) {
        request = (PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    }
    complement = "...";
    nom = "Init";
    System.out.println("Comp : " + complement);
}

Thanks for your comments. 感谢您的意见。 I just found out what was missing on my project : it's the jboss-deployment-structure.xml ! 我刚刚发现我的项目中缺少的东西:jboss-deployment-structure.xml! I added it with the dependencies and it worked, though I don't understand it yet. 我添加了依赖项,并且可以正常工作,尽管我还不了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM