Primefaces 数据表和 ViewScoped

Primefaces datatable and ViewScoped

我在 wildfly 8.2.0 (mojarra 2.2.8) 上使用 primefaces 5.0。

我尝试使用带有扩展的简单 primefaces 数据表,但每次扩展一行时,我的支持 bean @PostConstruct 都会被触发(它会重新加载数据,从而使 @ViewScoped 在第一名)。

我在 Whosebug 上看到过关于此问题的其他问题,但没有适合我的解决方案:

我的豆子:

@Named
@javax.faces.view.ViewScoped
@SuppressWarnings("serial")
public class TestBean implements Serializable {

    private List<String> things;

    @PostConstruct
    public void initialize() {
        System.out.println("initializing...");
        this.things = Arrays.asList("michael", "david", "paul");
    }

    public List<String> getThings() {
        return this.things;
    }
}

我的模板:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Test</title>
    </h:head>
    <h:body>
        <p:dataTable value="#{testBean.things}" var="thing">
            <p:column>
                <p:rowToggler />
            </p:column>
            <p:column>
                <h:outputText value="#{thing}" />
            </p:column>
            <p:rowExpansion>
                <h:outputText value="#{thing}" />
            </p:rowExpansion>
        </p:dataTable>
    </h:body>
</html>

要工作,<p:dataTable> 必须在 <h:form> 内。