I'm trying to create a bean using the view scope but the @PostConstruct function is called on every access of the bean. Here is a very simple example (.xhtml):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:outputText value="#{documentFormBeanTest.test()}" />
<h:outputText value="#{documentFormBeanTest.test()}" />
</html>
and here is my bean:
package lu.etat.pch.docroom.ejb.controllers;
import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import javax.inject.Named;
import java.io.Serializable;
/**
* User: André Faber
* Date: 22/04/13
*/
@Named
@ViewScoped
public class DocumentFormBeanTest implements Serializable {
@PostConstruct
public void init() {
System.out.println("*************************************************************");
}
public void test() {
System.out.println("Test");
}
}
now I can see in my log, that the PostConstruct function is called as often as I call the "test" function (in this case twice).
Shouldn't the bean be created only once (when I enter the page) or am I missing something?
Thanks in advance