English 中文(简体)
• 如何将浏览量输入数据: 表1
原标题:How to implement row numbering into h:dataTable

我有这份共同基金表格,有图谋。

<?xml version= 1.0  encoding= UTF-8  ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"    
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <ui:insert name="header">           
            <ui:include src="header.xhtml"/>         
        </ui:insert>
        <script type="text/javascript" src="resources/js/jquery-1.7.2.min.js"></script>
    </h:head>
    <h:body>

        <h1><img src="resources/css/images/icon.png" alt="DX-57" /> History Center</h1>
        <!-- layer for black background of the buttons -->
        <div id="toolbar" style="margin: 0 auto; width:1180px; height:30px; position:relative;  background-color:black">
            <!-- Include page Navigation -->
            <ui:insert name="Navigation">           
                <ui:include src="Navigation.xhtml"/>         
            </ui:insert>

        </div>  

        <div id="logodiv" style="position:relative; top:35px; left:0px;"> 
            <h:graphicImage alt="Dashboard"  style="position:relative; top:-20px; left:9px;"  value="resources/images/logo_sessions.png" />
        </div>
        <div id="main" style="margin: 0 auto; width:1190px; height:700px; position:absolute;  background-color:transparent; top:105px">

            <div id="mainpage" style="margin: 0 auto; width:1190px; height:500px; position:absolute;  background-color:transparent; top:80px">

                <div id="settingsHashMap" style="width:750px; height:400px; position:absolute;  background-color:r; top:20px; left:1px">

                    <h:form id="form">


                        <!-- The sortable data table -->
                        <h:dataTable id="dataTable" value="#{SessionsController.dataList}" var="item">
                            <!-- Check box -->
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Select" />
                                </f:facet>
                               <h:selectBooleanCheckbox onclick="highlight(this)" value="#{SessionsController.selectedIds[dataItem.id]}" />
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:commandLink value="Account Session ID" actionListener="#{SessionsController.sort}">
                                        <f:attribute name="sortField" value="Account Session ID" />
                                    </h:commandLink>
                                </f:facet>
                                <h:outputText value="#{item.aSessionID}" />
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:commandLink value="User ID" actionListener="#{SessionsController.sort}">
                                        <f:attribute name="sortField" value="User ID" />
                                    </h:commandLink>
                                </f:facet>
                                <h:outputText value="#{item.userID}" />
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:commandLink value="Activity Start Time" actionListener="#{SessionsController.sort}">
                                        <f:attribute name="sortField" value="Activity Start Time" />
                                    </h:commandLink>
                                </f:facet>
                                <h:outputText value="#{item.activityStart}" />
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:commandLink value="Activity End Time" actionListener="#{SessionsController.sort}">
                                        <f:attribute name="sortField" value="Activity End Time" />
                                    </h:commandLink>
                                </f:facet>
                                <h:outputText value="#{item.activityEnd}" />
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:commandLink value="Activity" actionListener="#{SessionsController.sort}">
                                        <f:attribute name="sortField" value="Activity" />
                                    </h:commandLink>
                                </f:facet>
                                <h:outputText value="#{item.activity}" />
                            </h:column>
                        </h:dataTable>

                        <f:verbatim><br/><hr /><br/></f:verbatim>


                        <table>
                            <tr>
                                <td>№</td>
                                <td>Select</td>
                                <td>Account Session ID</td>
                                <td>User ID</td>
                                <td>Activity Start Time</td>
                                <td>Activity End Time</td>
                                <td>Activity</td>
                            </tr>

                            <ui:repeat value="#{SessionsController.dataList}" var="i" varStatus="status">
                                <tr>
                                    <td>#{status.index + 1 + i.firstRow}</td>
                                    <td><h:selectBooleanCheckbox  value="#{i.selected}" /></td>
                                    <td><h:outputText value="#{i.aSessionID}" /></td>
                                    <td><h:outputText value="#{i.userID}" /></td>
                                    <td><h:outputText value="#{i.activityStart}" /></td>
                                    <td><h:outputText value="#{i.activityEnd}" /></td>
                                    <td><h:outputText value="#{i.activity}" /></td>
                                </tr>
                            </ui:repeat>
                        </table>
                        <!-- The paging buttons -->
                        <h:commandButton value="first" action="#{SessionsController.pageFirst}"
                                         disabled="#{SessionsController.firstRow == 0}" />
                        <h:commandButton value="prev" action="#{SessionsController.pagePrevious}"
                                         disabled="#{SessionsController.firstRow == 0}" />
                        <h:commandButton value="next" action="#{SessionsController.pageNext}"
                                         disabled="#{SessionsController.firstRow + SessionsController.rowsPerPage >= SessionsController.totalRows}" />
                        <h:commandButton value="last" action="#{SessionsController.pageLast}"
                                         disabled="#{SessionsController.firstRow + SessionsController.rowsPerPage >= SessionsController.totalRows}" />
                        <h:outputText value="Page #{SessionsController.currentPage} / #{SessionsController.totalPages}" />
                        <br />

                        <!-- The paging links -->
                        <ui:repeat value="#{SessionsController.pages}" var="page">
                            <h:commandLink value="#{page}" actionListener="#{SessionsController.page}"
                                           rendered="#{page != SessionsController.currentPage}" />
                            <h:outputText value="#{page}" escape="false"
                                          rendered="#{page == SessionsController.currentPage}" />
                        </ui:repeat>
                        <br />

                        <!-- Set rows per page -->
                        <h:outputLabel for="rowsPerPage" value="Rows per page" />
                        <h:inputText id="rowsPerPage" value="#{SessionsController.rowsPerPage}" size="3" maxlength="3" />
                        <h:commandButton value="Set" action="#{SessionsController.pageFirst}" />
                        <h:message for="rowsPerPage" errorStyle="color: red;" />

                    </h:form>                  

                </div>   

                <div id="settingsdivb" style="width:350px; height:400px; position:absolute;  background-color:transparent; top:20px; left:800px">

                </div>   
            </div>  
        </div>

        <script type="text/javascript">
              $("tr").not( :first ).hover(
              function () {
                $(this).css("background","#707070");
              }, 
              function () {
                $(this).css("background","");
              }
            );              

            function highlight(param) {  
            var row = jQuery(param).parent().parent().children();
                row.toggleClass( highlited );
            }        
        </script>

    </h:body>
</html>

我仅举一个简单的增长例子,用非常简单的“html”表来代表增长的数量。 在第二张表格中,图谋工作,但我不知道如何将<代码>ui:repeat纳入h:dataTable,以便实施行文计算。 我如何执行?

最佳回答

http://docs.oracle.com/javaee/6/api/javax/faces/component/UIData.html#getRowIndex%2829”rel=“noreferer”

<h:dataTable binding="#{table}" ...>
    <h:column>
        #{table.rowIndex + SessionsController.firstRow + 1}
    </h:column>
    ...
</h:dataTable>
问题回答

我不敢理解。 你们只是想一看一row子?

然而,我认为这并不容易。 h:数据 事实上,表没有支持。 混合 h:数据 表格和事实:重复似乎完全不正确(如果我正确理解的话)。

你可以:

  • http://myfaces.apache.org/tomahawk/index.html 你们可以像现在这样使用IndexVar Attribute:

    <t:dataTable rowIndexVar="row" value="#{someBean.value}">  
        <h:column>  
            <h:outputText value="#{row + 1}"/>  
        </h:column>  
    </t:dataTable>
    
  • 通常改变你的数据模式,并在内部提供指数。 或者使用一个包裹:

    public class DataWrapper{
        private int index;
        private Object model;
        // getter and setter
        ...
    }
    

    然后通过数据记录,而不是直接通过模型。 当然,你需要首先在您的服务层次上确定指数。

I hope this helps. Let me know if you need further assistance.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...