unable to use

on my primeface's datatable

2019-08-15 20:15发布

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

<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:

<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):

<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>

3条回答
Melony?
2楼-- · 2019-08-15 20:21

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.

Here is an example from the PrimeFaces documentation:

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

       ...columns

</p:dataTable>

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

The error you were getting: 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.

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:

<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.

FacesContext ctx = FacesContext.getCurrentInstance();
ExternalContext ectx = ctx.getExternalContext();
ServletContext sc = (ServletContext) ectx.getContext();
ectx.redirect("http://somedomain.org/somepage.html");
查看更多
Melony?
3楼-- · 2019-08-15 20:27

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.

查看更多
在下西门庆
4楼-- · 2019-08-15 20:39

Did you put editable=true inside your datatable? Try this:

<p:dataTable
    id="myDataTable"
    value="#{myBean.rowObjectList}
    var="rowObject"
    selection="#{myBean.selectedRowObject}"
    selectionMode="single" editable="true">
查看更多
登录 后发表回答