i am currently faced with strange problems with @PreDestroy methods in Mojarra 2.2.14: The behaviour seems to be some kind of undefined. sometimes it is called one time directly after @PostConstruct, sometimes it is called twice when triggering the GET again. same when leaving current page: sometimes clear() is called, but most times not. @PostConstruct on the the other hand works as expected.
the result ist, that all fields of ProductDetailBean are null, wenn calling page "productDetails.xhtml".
are there some known issues about that @PreDestroy? Would be very nice, if someown could give some helpful info about this. what would be suitable workarounds? this bean has a lot of fields and i have a strong interest to clear everything up when user leaves page.
Sadly i can not change to CDI-Beans for now...
@ManagedBean(name="productDetail") //javax.faces.bean.ManagedBean
@ViewScoped //javax.faces.bean.ViewScoped
public class ProductDetailBean implements Serializable {
private String field;
@PostConstruct
public void init(){
System.out.println("init Behaviour is ok, callend only once!");
this.field = "blah";
}
@PreDestroy
public void clear(){
System.out.println("called one or multiple times after init() ");
this.field = null;
}
public void setField(String field) {
this.field = field;
}
public String getField() {
return this.field;
}
}