简体   繁体   English

(JSF 2.0)primefaces dataTable组件存在问题。

[英](JSF 2.0) Problems with primefaces dataTable component.

I want to make a simple datatable just with the pagination feature, but i have 2 problems: 我只想使用分页功能制作一个简单的数据表,但是我有两个问题:

1- The data is displayed but the paginator is not shown in the browser(I tried IE and chrome) 1-显示数据,但在浏览器中未显示分页器(我尝试使用IE和chrome)

<p:dataTable var="garbage" value="#{resultsController.allGarbage}" paginator="true" rows="10">          

        <p:column>  
        <f:facet name="header">  
        <h:outputText value="Filename" />  
        </f:facet>  
        <h:outputText value="#{garbage.filename}" />
         </p:column> 

        <p:column>  
        <f:facet name="header">  
        <h:outputText value="Description" />  
        </f:facet>  
        <h:outputText value="#{garbage.description}" />  
         </p:column> 

        <p:column>  
        <f:facet name="header">  
        <h:outputText value="Upload date" />  
        </f:facet>  
        <h:outputText value="#{garbage.uploadDate}" /> 
         </p:column>                
</p:dataTable> 

2- In google chrome paginator still is not displayed and also i see some extrange dialog every time i refresh: 2-在谷歌浏览器chrome paginator仍然没有显示,并且每次刷新时我也会看到一些扩展对话框:

在此输入图像描述

Does this mean that primefaces is not compatible with chrome? 这是否意味着素面与铬不兼容?

------------------------UPDATE 1------------------------------ ------------------------更新1 ------------------------ ------

This is how it looks the hold page: 这是保留页面的外观:

<ui:composition template="WEB-INF/templates/BasicTemplate.xhtml">
<ui:define name="resultsForm">
<h:form enctype="multipart/form-data">
    <h:inputText id="search" value="" /><h:commandButton value="search"/>
    <h:selectOneRadio id="searchFilter" value="" >
            <f:selectItem id="r1" itemLabel="text documents(.pdf, .docx ...)" />
            <f:selectItem id="r2" itemLabel="audio(.mp3,.wav...)" />
            <f:selectItem id="r3" itemLabel="multimedia(.mpeg,flv...)" />
            <f:selectItem id="r4" itemLabel="other..." />               
    </h:selectOneRadio> 

    <p:dataTable var="garbage" value="#{resultsController.allGarbage}" paginator="true" rows="10"  
             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
             rowsPerPageTemplate="5,10,15">         

            <p:column>  
            <f:facet name="header">  
            <h:outputText value="Filename" />  
            </f:facet>  
            <h:outputText value="#{garbage.filename}" />
             </p:column> 

            <p:column>  
            <f:facet name="header">  
            <h:outputText value="Description" />  
            </f:facet>  
            <h:outputText value="#{garbage.description}" />  
             </p:column> 

            <p:column>  
            <f:facet name="header">  
            <h:outputText value="Upload date" />  
            </f:facet>  
            <h:outputText value="#{garbage.uploadDate}" /> 
             </p:column>                
    </p:dataTable> 
</h:form>
</ui:define>

------------------------UPDATE 2------------------------------ ------------------------更新2 ------------------------ ------

This image is how the component is displayed in chrome and how the chrome consoles displays an error: 此图像是组件在chrome中的显示方式以及chrome控制台如何显示错误: 在此输入图像描述

If you don't see any PrimeFaces specific CSS/JS imports in generated HTML <head> (rightclick page in browser, choose View Source , then it means that you need to replace the HTML <head> in your template by JSF <h:head> . That's namely where all resource dependencies (CSS/JS/images/etc which are connected to JSF components/libraries) will end up in. 如果在生成的HTML <head>没有看到任何PrimeFaces特定的CSS / JS导入(浏览器中的右键单击页面,选择View Source) ,则意味着您需要用JSF <h:head>替换模板中的HTML <head> <h:head> ,那就是所有资源依赖项(连接到JSF组件/库的CSS / JS / images / etc)都将在其中结束。

In former PrimeFaces versions (at least in 2.0) you would also need to configure a resource servlet to that PrimeFaces can serve them up from the JAR file: 在以前的PrimeFaces版本中(至少在2.0版中),您还需要配置一个资源servlet,以便PrimeFaces可以从JAR文件为它们提供服务:

<servlet>
    <servlet-name>Resource Servlet</servlet-name>
    <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Resource Servlet</servlet-name>
    <url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>

I'm however not sure about the newer PrimeFaces versions beyond 2.0, also currently the user manual is for some reason not free anymore. 但是我不确定2.0以后的最新PrimeFaces版本,目前由于某种原因,该用户手册已不再免费。

From the JS error it seems that the PrimeFaces javascript libraries are not correctly included. 从JS错误来看,似乎没有正确包含PrimeFaces javascript库。

I had the same issue with mojarra ("mojarra is not defined" in js console). 我在mojarra中遇到了相同的问题(js控制台中“ mojarra未定义”)。 It seems that for some reason the js libs are not included (should be done by the server). 似乎出于某种原因不包含js库(应由服务器完成)。 Sometimes they are, sometimes not (never found out the reason). 有时它们是,有时不是(从未找出原因)。

If anyone reading this has an idea, I would be thankful for any hint. 如果有任何读者有此想法,我将不胜感激。

For mojarre my workaround was to include mojarra's js lib manually. 对于mojarre,我的解决方法是手动包含mojarra的js lib。

Regarding to your problem, try the same for Primefaces. 关于您的问题,请对Primefaces尝试相同的操作。

In my project there is a page that uses p:dataTable and pagination. 在我的项目中,有一个页面使用p:dataTable和分页。 The following js files are included (plus some others; shown in source of html output): 包含以下js文件(以及其他js文件;显示在html输出中):

<script type="text/javascript" src="/register/primefaces_resource/2.1/yui/datasource/datasource-min.js"></script> 
<script type="text/javascript" src="/register/primefaces_resource/2.1/primefaces/paginator/paginator.js"></script> 
<script type="text/javascript" src="/register/primefaces_resource/2.1/yui/datatable/datatable-min.js"></script> 
<script type="text/javascript" src="/register/primefaces_resource/2.1/primefaces/datatable/datatable.js"></script> 
<script type="text/javascript" src="/register/primefaces_resource/2.1/yui/swf/swf-min.js"></script> 
<script type="text/javascript" src="/register/primefaces_resource/2.1/yui/charts/charts-min.js"></script> 
<script type="text/javascript" src="/register/primefaces_resource/2.1/primefaces/charts/charts.js"></script>

Look in your html ouput and check if the pagination-related js files are included. 查看您的html输出,并检查是否包含与分页相关的js文件。 If not, include them manually. 如果不是,请手动包括它们。 Note that /register in the src attributes is my context path. 请注意,src属性中的/register是我的上下文路径。 Replace it with your context path. 用您的上下文路径替换它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM