在p:dataTable中调用一个@ViewScoped bean的构造函数。

时间:2022-09-17 10:54:10

Why h:commandLink inside p:dataTable calls the constructor of a @ViewScoped bean?

为什么h:commandLink在p:dataTable中调用@ViewScoped bean的构造函数?

JSF 2.1.8 + Primefaces 3.4 + Tomcat 6.0.35

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.

当我点击“一个”或“两个”init时,再次调用。

1 个解决方案

#1


1  

For the time being, two solutions:

目前,有两种解决方案:

  1. Remove primefaces references. Use h:dataTable and h:column instead.

    删除primefaces引用。使用h:dataTable和h:列代替。

  2. Downgrade to primefaces 3.3.1 (take a look at http://forum.primefaces.org/viewtopic.php?f=3&t=24676)

    下调至primefaces 3.3.1(查看http://forum.primefaces.org/viewtopic.php?

#1


1  

For the time being, two solutions:

目前,有两种解决方案:

  1. Remove primefaces references. Use h:dataTable and h:column instead.

    删除primefaces引用。使用h:dataTable和h:列代替。

  2. Downgrade to primefaces 3.3.1 (take a look at http://forum.primefaces.org/viewtopic.php?f=3&t=24676)

    下调至primefaces 3.3.1(查看http://forum.primefaces.org/viewtopic.php?