Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 JSF2-h:commandLink在p:dataTable中调用@viewscope bean的构造函数_Jsf 2_Primefaces - Fatal编程技术网

Jsf 2 JSF2-h:commandLink在p:dataTable中调用@viewscope bean的构造函数

Jsf 2 JSF2-h:commandLink在p:dataTable中调用@viewscope bean的构造函数,jsf-2,primefaces,Jsf 2,Primefaces,为什么p:dataTable中的h:commandLink调用@ViewScope bean的构造函数 JSF2.1.8+PrimeFaces3.4+Tomcat6.0.35 一些 - 简单页面cotaco.xhtml - @ManagedBean @视域 公共类DAMB实现可序列化{ private List=Arrays.asList(“一”、“二”);//省略了getter和setter @施工后 公共void init(){ System.out.println(“噢,不!”);

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

JSF2.1.8+PrimeFaces3.4+Tomcat6.0.35


一些
-


简单页面cotaco.xhtml
-

@ManagedBean
@视域
公共类DAMB实现可序列化{
private List=Arrays.asList(“一”、“二”);//省略了getter和setter
@施工后
公共void init(){
System.out.println(“噢,不!”);
}
}
当我点击“一”或“二”时,再次调用init


目前,有两种解决方案:

  • 删除引用。改用h:dataTable和h:column

  • 降级至primefaces 3.3.1(查看)


  • 它通常不会这样做。我建议你重新提出问题,询问具体问题,而不是错误的结论。@BalusC Done!你能帮我吗?
    cotaco
    是当前视图的标识符还是不同视图的标识符?如果不同,bean是否也在其中引用?bean究竟是什么时候构造的?在
    init()
    方法中打印
    FacesContext#getCurrentPhaseId()
    。同时,我建议阅读以了解一个视图范围的bean应该存活多长时间。@balusccotacao是一个简单的页面(有问题的更新)。我的输出:访问页面时“RENDER_RESPONSE 6”。单击链接时“调用应用程序5”。好的。我还是不明白原因。但是,您的第一页在语法上无效。表单应放入
    。或者你真的有更多的代码吗?我不能用3.5复制,没有用3.4尝试。试着把你的mojarra升级到最新版本。@CagatayCivici你好,老板。我可以使用3.5在一个非常简单的maven项目中复制它。我相信这是一个关键的错误。瞧@celinHC我用了h:datatable而不是p:datatable我的问题得到了解决,但无法使用primefaces datatable功能。。到目前为止,您还发现了其他解决方法吗???
    <?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!");
        }
    }