1

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>

Emil Sierżęga
  • 1,785
  • 2
  • 31
  • 38
cascadox
  • 893
  • 4
  • 14
  • 32

3 Answers3

2

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");
Jim Tough
  • 14,843
  • 23
  • 75
  • 96
  • hey thanks for your answer what i want to do is call my function by selecting a row this function will redirect me to another page so i already tryed the example you posted but it's doesn't work, so i thought that may be i should try the instant row example: http://www.primefaces.org/showcase-labs/ui/datatableRowSelectionInstant.jsf but still not working neither... – cascadox Jul 29 '11 at 00:32
  • here is my very simple function: public String redirection() { return "projetdetails"; } – cascadox Jul 29 '11 at 00:33
  • also here is my navigation case: /datatablenavigationtest.xhtml projetdetails /infoprojet.xhtml – cascadox Jul 29 '11 at 00:37
  • thanks for your answer but i still have the same error : Parent not an instance of ClientBehaviorHolder: org.primefaces.component.datatable.DataTable the strage thing is that i'm using 3.0.M1 so i should work unless my primefaces integration is not done properly so you may have a look on my pom.xml above and tell what you think... – cascadox Jul 30 '11 at 14:53
  • PrimeFaces 3.0-M1 was a terrible release. You should at least start using 3.0-M2 or just use the 3.0-M3-SNAPSHOT builds. Your pom file would lead me to believe that you already are. – Jim Tough Jul 30 '11 at 21:26
  • ok so i should change my version by adding: org.primefaces primefaces 3.0.M2 i will try and tell you the result thanks for your time – cascadox Jul 31 '11 at 00:00
  • It looked like you were already using the M3-SNAPSHOT. That's what I'm using. I can't tell you exactly what to put in the version in your pom because I'm not using Maven on my project (because my customer doesn't use Maven). I have to download the PrimeFaces JAR myself and add it to my project classpath. I manually get a new copy of the M3-SNAPSHOT every few days. – Jim Tough Jul 31 '11 at 01:09
  • Looks correct. Can you edit your question and add the code for your method: `projet.redirection()` – Jim Tough Aug 02 '11 at 18:31
  • Here is a related question: http://stackoverflow.com/questions/3539992/fajax-unable-to-attach-fajax-to-non-clientbehaviorholder-parent. Are you sure that your current code does not have any `` or `` tags nested directly inside a ``? – Jim Tough Aug 02 '11 at 18:52
  • done i had put the method's code, and yes i have an ajax tag nested directly inside the datatable as my code posted before shows andi'm using primefaces 3.0.M3 Snapshot so i shouldn't have this error, i'm using netbeans 7 that already integrate primefaces 2.2.1... if that might help, it is a conflict between versions? – cascadox Aug 03 '11 at 09:28
  • Sorry, I meant OTHER tags. :) I was looking at this line in your code: ``. I wanted to see the method signature for the `redirection()` method, not `reformulation()` because that is the method referenced in your Ajax tag. – Jim Tough Aug 03 '11 at 12:05
  • sorry i forgot but its the same method just changed the name :) – cascadox Aug 03 '11 at 12:27
  • Your method takes `ActionEvent` as a parameter. The `` is expecting `SelectEvent` as the parameter. – Jim Tough Aug 03 '11 at 12:37
  • In the example given above by Jim, `#myBean` should implement `org.primefaces.model.SelectableDataModel` interface when selection is enabled. – user640554 May 26 '12 at 01:18
1

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">
Catfish
  • 18,876
  • 54
  • 209
  • 353
Praveen
  • 11
  • 1
1

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.

Aamir
  • 655
  • 1
  • 8
  • 27