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

时间:2011-07-28 08:54:16

标签: ajax jsf datatable jsf-2 primefaces

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

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

所以我做了一些研究,我认为这是一个旧版本的问题,所以我已经将我的版本更新为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>     

这是我的函数代码:

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");
}

也许我没有正确地集成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>

3 个答案:

答案 0 :(得分:2)

请勿尝试将<p:ajax>放入<p:dataTable>内。这是PrimeFaces组件之一,您可以在组件本身中声明与Ajax相关的属性。

以下是PrimeFaces文档中的一个示例:

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

       ...columns

</p:dataTable>

了解rowSelectListener

中如何正确声明<p:dataTable>属性?

您获得的错误: 父级不是ClientBehaviorHolder的实例

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

修改

我的错!我在家里回复,无法访问使用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>

以下是我的听众方法签名:

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

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

我对您的网络应用程序了解不足以了解您的重定向是如何工作的,但我还会在用户单击“注销”按钮后向您提供我在webapp中使用的代码示例,然后重定向它们到“你已登出”页面。此代码是从操作方法调用的。

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

答案 1 :(得分:1)

尝试保留一罐主要表面,即2.1.1或3.1.1不是两者,它们会产生冲突。 它对我来说也是同样的错误,希望你的意志也能得到解决。

答案 2 :(得分:1)

您是否将editable=true放入数据表中?试试这个:

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