JSF Bean & Bean Constructor

Posted by Jagadeesh VP | Posted in

Using constructor in bean class will make all the references from faces-config.xml to null.
This throws the exception.

But for some bean constructor in necessary for initialization.

This problem can be avoided by using @PostConstruct annotation.

Eg:

public MyBean(){
someMethod();
}
the above constructor can be replaced by

@PostConstruct
public void myBeanMethod(){
someMethod();
}

The method defined with this annotation will be called immediately after finishing the construction of Bean object.

Note : This annotation won't works in JSF 1.1

Comments (0)

Post a Comment