Why h:commandLink inside p:dataTable calls the constructor of a @ViewScoped bean?
JSF 2.1.8 + Primefaces 3.4 + Tomcat 6.0.35
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core" lang="en">
<h:body>
<h:form>
<p:dataTable var="item" value="#{realizadaMB.list}">
<p:column>
<f:facet name="header">
Some
</f:facet>
<h:commandLink action="cotacao" value="#{item}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
Simple page cotacao.xhtml
</html>
-
@ManagedBean
@ViewScoped
public class RealizadaMB implements Serializable {
private List<String> list = Arrays.asList("one", "two"); //getter and setter omitted
@PostConstruct
public void init() {
System.out.println("Oh no!");
}
}
When i click in "one" or "two" init is called again.
cotacao
the identifier of the current or a different view? If different, is the bean also referenced in there? When exactly is the bean constructed? PrintFacesContext#getCurrentPhaseId()
in theinit()
method. In the meanwhile, I suggest to read stackoverflow.com/questions/4831888/… to learn how long a view scoped bean is supposed to live. – BalusC<h:body>
. Or did you actually have more into the code? – BalusC