为什么Jquery数据表无法使用richfaces <a4j:repeat>?</a4j:repeat>

时间:2015-02-12 08:47:02

标签: javascript jquery jsf datatables richfaces

我使用JSF2.2和Richfaces 4,我尝试使用Jquery的Datatables创建一个表。 因为我的所有数据都是动态的,所以我必须使用它。 但它在jsf中给了我一个空表。

这是我的jsf页面:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:p="http://java.sun.com/jsf/passthrough"
xmlns:rich="http://richfaces.org/rich">
<h:head>
    <script type="text/javascript" src="js/jquery.dataTables.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css"/>
<script> 
$(document).ready(function() {
    $('#example').dataTable();
} );
</script>
</h:head>
<h:body>
    <h:form>
        <h:panelGroup id="tableau">
            <table id="example" class="display compact" cellspacing="0"
                width="100%">


                <a4j:repeat value="#{auditController.findAllEntityList()}"
                    var="entity" rowKeyVar="rowentity">


                    <thead>
                        <tr>
                            <a4j:repeat
                                value="#{Controller.findP(entity).entrySet().toArray()}"
                                var="entete1">
                                <th><h:outputLabel value="#{entete1.key}"
                                        rendered="#{rowentity eq 0 and  entete1.key !='class'}" /></th>
                            </a4j:repeat>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <a4j:repeat
                                value="#{Controller.findP(entity).entrySet().toArray()}"
                                var="entete">
                                <td><h:outputLabel value="#{entete.value}"/></td>
                            </a4j:repeat>
                            </tr>
                    </tbody>
                </a4j:repeat>

            </table>
        </h:panelGroup>
    </h:form>
</h:body>

没有Jquery,它可以很好地工作。

1 个答案:

答案 0 :(得分:0)

我将<a4j:repeat>替换为<ui:repeat>并且效果很好。所以我的代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://java.sun.com/jsf/passthrough"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
    <title>test-test</title>
    <link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css" />
    <link rel="stylesheet" type="text/css" href="css/shCore.css" />
    <link rel="stylesheet" type="text/css" href="css/demo.css" />
    <style type="text/css" class="init">
</style>
    <script type="text/javascript" language="javascript" src="js/jquery.js"></script>
    <script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
    <script type="text/javascript" language="javascript" src="js/shCore.js"></script>
    <script type="text/javascript" language="javascript" src="js/demo.js"></script>
    <script type="text/javascript" language="javascript">
$(document).ready(function() {
$('#example').dataTable({
    "bPaginate": true,
    "bFilter": false,
    "bInfo": false,
    "bProcessing" : false,
    "bJQueryUI" : true,
    "sEmptyTable" : "No messages found",
    });} );


</script>
</h:head>
<h:body class="exampleLos">
    <h:form>
    <h:panelGroup id="tableau">
            <table id="example" class="display compact" cellspacing="0" width="100%">
                <ui:repeat var="entity"
                    value="#{Controller.fAllList()}" varStatus="KeyVarSta">
                    <thead>
                        <tr>
                            <ui:repeat
                                value="#{Controller.fPropreties(KeyVarSta.index).entrySet().toArray()}" var="entete1">
                                <th><h:outputLabel value="#{entete1.key}" rendered="#{KeyVarSta.index == 0 and  entete1.key !='class'}" /></th>
                            </ui:repeat>
                            <th><h:outputLabel value="Rev" rendered="#{KeyVarSta.index == 0}" /></th>
                            <th><h:outputLabel value="Rev Date" rendered="#{KeyVarSta.index == 0}" /></th>
                            <th><h:outputLabel value="Rev User" rendered="#{KeyVarSta.index == 0}" /></th>
                            <th><h:outputLabel value="Rev Type" rendered="#{KeyVarSta.index == 0}" /></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <ui:repeat
                                value="#{Controller.fPropreties(KeyVarSta.index).entrySet().toArray()}" var="entete">
                                <td><h:outputLabel value="#{entete.value}"rendered="#{entete.key !='class'}" /></td>
                            </ui:repeat>
                            <td><h:outputLabel
                                    value="#{Controller.findREny(KeyVarSta.index).rev}" /></td>
                            <td><h:outputLabel
                                    value="#{Controller.findREny(KeyVarSta.index).revdate}">
                                </h:outputLabel></td>
                            <td><h:outputLabel
                                    value="#{Controller.findREny(KeyVarSta.index).username}" /></td>
                            <td><h:outputLabel
                                    value="#{Controller.findREnyType(KeyVarSta.index).name()}" /></td>
                        </tr>
                    </tbody>
                </ui:repeat>
            </table>
        </h:panelGroup>
    </h:form>
</h:body>