无法在我的 primeface 的数据表上使用 <p:ajax>

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6856367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 11:02:56  来源:igfitidea点击:

unable to use <p:ajax> on my primeface's datatable

ajaxjsfdatatablejsf-2primefaces

提问by cascadox

I'm having some problems with datatable's instant row selection, exactly <p:ajax/>. It's giving me this error:

我在数据表的即时行选择方面遇到了一些问题,正是<p:ajax/>. 它给了我这个错误:

<p:ajax> Parent not an instance of ClientBehaviorHolder:
org.primefaces.component.datatable.DataTable

So I did some research and I think it's a problem with an old version, so I've updated my version to 3.0.M3-SNAPSHOT but I have still the same error and I wonder why!
Here is my page code:

所以我做了一些研究,我认为这是旧版本的问题,所以我已经将我的版本更新为 3.0.M3-SNAPSHOT 但我仍然出现同样的错误,我想知道为什么!
这是我的页面代码:

<p:dataTable id="projets"  var="p" value="#{projet.init()}" selection="#{projet.currentChangerStatus}" selectionMode="single">  

    <p:ajax event="rowSelect" listener="#{projet.redirection}" update="formEquipe" oncomplete="projetDialog.show()" />  
        <f:facet name="header">  
            Select a row to display a message  
        </f:facet>
        <p:column headerText="Code" sortBy="#{p.projets.codeProjet}" filterBy="#{p.projets.codeProjet}">
           <h:outputText value="#{p.projets.codeProjet}" />
        </p:column>

        <p:column headerText="Intitulé">
            <h:outputText value="#{p.projets.libelle}" />
        </p:column>

        <p:column headerText="Dérnier Etat">
            <h:commandLink id="link1" action="goto5">
                <h:outputText value="#{p.etats.libelleEtat}" />
            </h:commandLink>
        </p:column>

        <p:column headerText="Etat Changé Au Niveau">                      
            <h:outputText value="xxxx" />                        
        </p:column>

        <p:column headerText="Date Dérnier Etat">
            <h:outputText value="#{p.dateTache}" />
        </p:column>

        <p:column headerText="Responsable Etat">
            <h:outputText value="#{p.acteurs.nomActeur}" />
        </p:column>

        <p:column headerText="Objets | Application">
            <h:commandLink id="link2" action="goto4">
                <h:outputText value="xxxx" />
            </h:commandLink>
        </p:column>

        <p:column headerText="Domaine">
            <h:outputText value="#{p.projets.domaines.libelleDomaine}" />
        </p:column>

        <p:column headerText="Type">
            <h:outputText value="#{p.projets.typeProjets.libelleTypeProjet}" />
        </p:column>

        <p:column headerText="CP">
            <h:commandLink id="link3" action="goto3">
                <h:outputText value="xxxx" />
            </h:commandLink>
        </p:column>

        <p:column headerText="Plan Int.">
            <h:commandLink id="link4" action="goto2">
                <h:outputText value="xxxx" />
            </h:commandLink>
        </p:column>

        <p:column headerText="Doc Principal">
            <h:commandLink id="link5" action="goto1">
                <h:outputText value="xxxx" />
            </h:commandLink>
        </p:column>

        <p:column headerText="Dérnier Motif">
            <h:outputText value="xxxx" />
        </p:column>

        <p:column headerText="Auteur">
            <h:outputText value="xxxx" />
        </p:column>

        <p:column style="width:80px">
            <h:panelGrid columns="3" styleClass="actions" cellpadding="2">  
                <p:commandButton update=":form:display" oncomplete="carDialog.show()"
                actionListener="#{projet.redirection}"  image="ui-icon ui-icon-search" title="View">  
                    <f:setPropertyActionListener value="xxxx" target="xxxx" />  
                    <f:setPropertyActionListener value="xxxx" target="xxxx" />  
                </p:commandButton>  
                <p:commandButton update=":form:display" oncomplete="carDialog.show()"
                    image="ui-icon ui-icon-pencil" title="Edit">  
                    <f:setPropertyActionListener value="xxxx" target="xxxx" />  
                    <f:setPropertyActionListener value="xxxx" target="xxxx" />  
                </p:commandButton>  
                <p:commandButton update=":form:display" oncomplete="confirmation.show()"
                    image="ui-icon ui-icon-close" title="Delete">  
                    <f:setPropertyActionListener value="xxxx" target="xxxx" />  
                </p:commandButton>  
            </h:panelGrid>  
        </p:column>             
     </p:dataTable>  
     <p:dialog header="Car Detail" widgetVar="projetDialog" resizable="false" width="200" showEffect="clip" hideEffect="fold">  
        <h:panelGrid id="display" columns="2" cellpadding="4">  
            <f:facet name="header">  
                <p:graphicImage value="/images/cars/xxxx.jpg"/>  
            </f:facet>  

            <h:outputText value="Etat:" />  
            <h:outputText value="#{projet.currentChangerStatus.etats.libelleEtat}" />

            <h:outputText value="Date Reception:" />  
            <h:outputText value="#{projet.currentChangerStatus.projets.dateReceptionProjet}" />

            <h:outputText value="Libelle" />  
            <h:outputText value="xxxx" />  

            <h:outputText value="Acteur:" />  
            <h:outputText value="xxxx" />  
        </h:panelGrid>  
    </p:dialog>     

Here is my function's code:

这是我的函数代码:

public void redirection(SelectEvent event) throws Exception {
    System.out.println("some message: " );
    currentChangerStatus=(ChangerStatus)event.getObject();
    currentProjet=currentChangerStatus.getProjets();
    System.out.println("le projet est  : " +currentProjet.getLibelle());
    FacesContext.getCurrentInstance().getExternalContext().redirect("infoprojet.xhtml");
}

Maybe I didn't integrated the Primefaces jar correctly, so here is my POM(maven):

也许我没有正确集成 Primefaces jar,所以这是我的POM(maven):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany</groupId>
<artifactId>Gpsi</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>Gpsi Web App</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <netbeans.hint.deploy.server>Tomcat70</netbeans.hint.deploy.server>
</properties>

 <dependencies>
    <!-- Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.2.5.ga</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.3.2.GA</version>
    </dependency>



    <dependency>
       <groupId>cglib</groupId>
       <artifactId>cglib-nodep</artifactId>
       <version>2.1_3</version>
    </dependency>
    <!-- Hibernate query library dependecy start -->
<dependency>
       <groupId>antlr</groupId>
       <artifactId>antlr</artifactId>
       <version>2.7.6</version>
    </dependency>


        <!--ASM-->
    <dependency>
       <groupId>asm</groupId>
       <artifactId>asm</artifactId>
       <version>1.5.3</version>
    </dependency>


    <dependency>
        <groupId>javax.sql</groupId>
        <artifactId>jdbc-stdext</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.0.1B</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>ejb3-persistence</artifactId>
        <version>1.0.1.GA</version>
    </dependency>
    <dependency>
        <groupId>unknown.binary</groupId>
        <artifactId>ojdbc14</artifactId>
        <version>SNAPSHOT</version>
    </dependency>
    <!--Primefaces-->
    <dependency>
                <groupId>org.primefaces</groupId>
                <artifactId>primefaces</artifactId>
                <version>3.0.M3-SNAPSHOT</version>
    </dependency>
     <!--End Primefaces-->
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>

     <dependency>     
        <groupId>javax.el</groupId>
        <artifactId>el-api</artifactId>
        <version>2.2</version>
        <scope>provided</scope>
      </dependency>

      <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>el-impl</artifactId>
        <version>2.2</version>
        <scope>provided</scope>
      </dependency>

      <!-- Spring framework --> 
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring</artifactId>
  <version>2.5.6</version>
</dependency>

    <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
  <version>2.5.6</version>

</dependency>

    <dependency>
      <groupId>org.springframework</groupId>
  <artifactId>spring-tx</artifactId>
  <version>2.5.6</version>
</dependency>

    <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-aop</artifactId>
  <version>2.5.6</version>
</dependency>

    <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-beans</artifactId>
  <version>2.5.6</version>
</dependency>

    <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>2.5.6</version>
</dependency>

    <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>2.5.6</version>
</dependency>

    <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jdbc</artifactId>
  <version>2.5.6</version>
</dependency>

    <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-orm</artifactId>
  <version>2.5.6</version>
</dependency>
    <!-- Apach commons --> 
    <!-- dbcp pour la data source --> 
    <dependency>
       <groupId>commons-dbcp</groupId>
       <artifactId>commons-dbcp</artifactId>
       <version>1.2.2</version>
    </dependency>

    <dependency>
       <groupId>commons-pool</groupId>
       <artifactId>commons-pool</artifactId>
       <version>1.4</version>
    </dependency>

    <dependency>
       <groupId>commons-collections</groupId>
       <artifactId>commons-collections</artifactId>
       <version>3.2</version>
    </dependency>
     <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.0.4-b09</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.0.4-b09</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.1.2</version>
    </dependency>
    <!-- Themes -->
    <dependency>
        <groupId>org.primefaces.themes</groupId>
        <artifactId>aristo</artifactId>
        <version>1.0.1</version>
    </dependency>
    <!-- FIN Themes -->
    <!-- Upload library -->
    <dependency>
       <groupId>commons-fileupload</groupId>
       <artifactId>commons-fileupload</artifactId>
       <version>1.2.2</version>
    </dependency>

    <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <version>2.0.1</version>
    </dependency>
    <!-- Fin Upload library -->
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>
   <!-- iText-->
   <dependency>

  <groupId>com.itextpdf</groupId>
  <artifactId>itextpdf</artifactId>
  <version>5.0.4</version>
  <scope>compile</scope>

</dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>6.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <finalName>Gpsi</finalName>
</build>
<repositories>
    <repository>
        <url>http://download.java.net/maven/2/</url>
        <id>jsf20</id>
        <layout>default</layout>
        <name>Repository for library Library[jsf20]</name>
    </repository>
    <repository>
        <url>http://repository.prime.com.tr/</url>
        <id>primefaces</id>
        <layout>default</layout>
        <name>Repository for library Library[primefaces]</name>
    </repository>
    <repository>
        <id>unknown-jars-temp-repo</id>
        <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
        <url>file:${project.basedir}/lib</url>
    </repository>
    <repository>
  <id>itextpdf.com</id>
  <name>Maven Repository for iText</name>

  <url>http://maven.itextpdf.com/</url>
</repository>
</repositories>

回答by Jim Tough

Don't try to put a <p:ajax>inside the the <p:dataTable>. This is one of the PrimeFaces components where you declare the Ajax-related attributes right in the component itself.

不要试图将 a<p:ajax>放入<p:dataTable>. 这是 PrimeFaces 组件之一,您可以在其中在组件本身中声明与 Ajax 相关的属性。

Here is an example from the PrimeFaces documentation:

以下是 PrimeFaces 文档中的示例:

<p:dataTable 
    var="car" 
    value="#{carBean.cars}" 
    selectionMode="single"
    selection="#{carBean.selectedCar}"
    onRowSelectUpdate="carListForm:dialogContent"
    rowSelectListener="#{carBean.onCarSelect}">

       ...columns

</p:dataTable>

See how the rowSelectListenerattribute is declared right inside the <p:dataTable>?

看看rowSelectListener属性是如何在<p:dataTable>?

The error you were getting: Parent not an instance of ClientBehaviorHolder

你得到的错误: Parent not an instance of ClientBehaviorHolder

This means that the parent tag cannot contain an Ajax tag. The example above is from the PrimeFaces 2.2 documentation, but I believe 3.0 is similar.

这意味着父标记不能包含 Ajax 标记。上面的例子来自 PrimeFaces 2.2 文档,但我相信 3.0 是相似的。

EDIT:

编辑:

My mistake! I replied from home and didn't have access to my code that uses PrimeFaces 3.0. In PF 3.0 (unlike PF 2.2) you can embed the <p:ajax>element. Here is a code sample that works for me:

我的错!我在家里回复了,但无法访问我使用 PrimeFaces 3.0 的代码。在 PF 3.0(与 PF 2.2 不同)中,您可以嵌入<p:ajax>元素。这是一个对我有用的代码示例:

<p:dataTable
        id="myDataTable"
        value="#{myBean.rowObjectList}
        var="rowObject"
        selection="#{myBean.selectedRowObject}"
        selectionMode="single">

    <p:ajax
        event="rowSelect"
        listener="#{myBean.onRowSelect}"
        update="someElement" />
    <p:ajax
        event="rowUnselect"
        listener="#{myBean.onRowUnselect}"
        update="someElement" />



</p:dataTable>

Here are my listener methods signatures:

这是我的侦听器方法签名:

public void onRowSelect(SelectEvent event) {
    // your code here...
}

public void onRowUnselect(UnselectEvent event) {
    // your code here...
}

I don't know enough about your webapp to understand how your redirect is meant to work, but I will also give you a code sample that I'm using in my webapp after the user clicks a Logout button and I redirect them to a "you are logged out" page. This code is called from an action method.

我对你的 webapp 了解得不够多,无法理解你的重定向是如何工作的,但我也会给你一个代码示例,在用户单击“注销”按钮并将它们重定向到“您已退出”页面。此代码是从操作方法调用的。

FacesContext ctx = FacesContext.getCurrentInstance();
ExternalContext ectx = ctx.getExternalContext();
ServletContext sc = (ServletContext) ectx.getContext();
ectx.redirect("http://somedomain.org/somepage.html");

回答by aamir

try to keep one jar of primefaces i.e. either 2.1.1 or 3.1.1 not both, they create conflicts. it works for me for the same error hopefully your will resolved as well.

尽量保留一罐 primefaces,即 2.1.1 或 3.1.1 不是两者,它们会造成冲突。对于同样的错误,它对我有用,希望您也能解决。

回答by Praveen

Did you put editable=trueinside your datatable? Try this:

你把你的数据表放在editable=true里面了吗?尝试这个:

<p:dataTable
    id="myDataTable"
    value="#{myBean.rowObjectList}
    var="rowObject"
    selection="#{myBean.selectedRowObject}"
    selectionMode="single" editable="true">