为什么 p:dataTable 中的 h:commandLink 调用 @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!");
}
}
当我单击“一个”或“两个”时,会再次调用 init。