【问题标题】:Show nested datatable without repeating original data显示嵌套数据表而不重复原始数据
【发布时间】:2015-04-28 20:38:56
【问题描述】:

我想显示数据库中的数据但不能重复相同的配置文件,只需在现有配置文件中添加一个位置。有了上面的例子就清楚了:

+-------------------+---------------+---------------+
|   PROFILE         |   LOCATION    |   STATUS      |
+-------------------+---------------+---------------+
+-------------------+---------------+---------------+
|   Admin           |   Chief       |   OK          |
+-------------------+---------------+---------------+
|   Director        |   Supervision |   OK          |
+-------------------+---------------+---------------+
|   Secretary       |   Supervision |   OK          |
+-------------------+---------------+---------------+
|                   |   Admin       |   OK          |
|                   |   Chief       |   OK          |
|   Chief-accessor  |   Director    |   OK          |
|                   |   Secretary   |   OK          |
|                   |   Supervision |   OK          |
+-------------------+---------------+---------------+

这段代码是我的数据表,我只能重复它们,但我不能对它们进行分组:

<rich:panel header="User location info" style="margin: 20px 0 !important;">
    <h:dataTable id="userLocationList"
        value="#{userLocation.list()}" var="row"
        styleClass="rich-table"
        headerClass="rich-table-subheader rich-table-subheadercell rich-table-thead"
        rowClasses="rich-table-row"
        columnClasses="rich-table-cell,rich-table-cell,rich-table-cell">
        <h:column>
            <f:facet name="header">
                <h:outputText value="Profile" />
            </f:facet>
            <center>
                <h:outputText value="#{row.profile}" />
            </center>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputText value="Location" />
            </f:facet>
            <h:outputText value="#{row.location}" />
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputText value="Status" />
            </f:facet>
            <center>
                <h:outputText value="#{row.profile.status ? 'OK' : 'Inactive'}" />
            </center>
        </h:column>
    </h:dataTable>
</rich:panel>

像这样:

+-------------------+---------------+---------------+
|   PROFILE         |   LOCATION    |   STATUS      |
+-------------------+---------------+---------------+
+-------------------+---------------+---------------+
|   Admin           |   Chief       |   OK          |
+-------------------+---------------+---------------+
|   Director        |   Supervision |   OK          |
+-------------------+---------------+---------------+
|   Secretary       |   Supervision |   OK          |
+-------------------+---------------+---------------+
|   Chief-accessor  |   Admin       |   OK          |
+-------------------+---------------+---------------+
|   Chief-accessor  |   Chief       |   OK          |
+-------------------+---------------+---------------+
|   Chief-accessor  |   Director    |   OK          |
+-------------------+---------------+---------------+
|   Chief-accessor  |   Secretary   |   OK          |
+-------------------+---------------+---------------+
|   Chief-accessor  |   Supervision |   OK          |
+-------------------+---------------+---------------+

来自UserLocation 的方法list() 只是table_user_location 中的select

select userLoc from UserLocation userLoc where userLoc.user.id = :userId

我尝试在 StackOverflow 中遵循一些答案,即将数据表放入另一个数据表中,但我可以重复所有没有组配置文件的位置,例如:

+-------------------+---------------+---------------+
|   PROFILE         |   LOCATION    |   STATUS      |
+-------------------+---------------+---------------+
+-------------------+---------------+---------------+
|                   |   Chief       |               |
|                   |   Supervision |               |
|                   |   Supervision |               |
|                   |   Admin       |               |
|   Admin           |   Chief       |   OK          |
|                   |   Director    |               |
|                   |   Secretary   |               |
|                   |   Supervision |               |
+-------------------+---------------+---------------+
|                   |   Chief       |               |
|                   |   Supervision |               |
|                   |   Supervision |               |
|                   |   Admin       |               |
|   Director        |   Chief       |   OK          |
|                   |   Director    |               |
|                   |   Secretary   |               |
|                   |   Supervision |               |
+-------------------+---------------+---------------+
|                   |   Chief       |               |
|                   |   Supervision |               |
|                   |   Supervision |               |
|                   |   Admin       |               |
|   Secretary       |   Chief       |   OK          |
|                   |   Director    |               |
|                   |   Secretary   |               |
|                   |   Supervision |               |
+-------------------+---------------+---------------+
|                   |   Chief       |               |
|                   |   Supervision |               |
|                   |   Supervision |               |
|                   |   Admin       |               |
|   Chief-accessor  |   Chief       |   OK          |
|                   |   Director    |               |
|                   |   Secretary   |               |
|                   |   Supervision |               |
+-------------------+---------------+---------------+
|                   |   Chief       |               |
|                   |   Supervision |               |
|                   |   Supervision |               |
|                   |   Admin       |               |
|   Chief-accessor  |   Chief       |   OK          |
|                   |   Director    |               |
|                   |   Secretary   |               |
|                   |   Supervision |               |
+-------------------+---------------+---------------+
And so it goes...

我怀疑我正在做的通用查询,所以表中的重复内容。有人对这个操作有想法吗?

相关问题:

【问题讨论】:

    标签: jsf richfaces


    【解决方案1】:

    由于我无法按照他们返回相同配置文件的所有位置并仅使用一个查询的方式来做到这一点,因此我决定采取不同的做法,我想使用两个查询,一个用于所有没有重复配置文件的查询 (select distinct ... ) 并且根据配置文件为每个位置提供一个。只意识到(如果我错了,请纠正我)属性h:datatable 按列而不是按行呈现。因此,部分地,第一个配置文件列在没有重复配置文件的情况下全部返回,但是如果位置将出现的单元格属于给定配置文件,则每个单元格中的位置都相同,所有用户位置都没有区别。那时我意识到我非常专注于关注用户个人资料的地方。

    运行select distinct 配置文件并创建一个方法来返回创建表时配置文件的位置。正如报告的问题一样,datatable 位于另一个 datatable 中。

    终于拿到了我的代码:

    <rich:panel header="Informations" style="margin: 20px 0 !important;">
        <h:dataTable id="userLocationList"
            value="#{userLocation.list()}" var="row"
            styleClass="rich-table"
            headerClass="rich-table-subheader rich-table-subheadercell rich-table-thead"
            rowClasses="rich-table-row"
            columnClasses="rich-table-cell,rich-table-cell,rich-table-cell">
            <h:column>
                <f:facet name="header">
                    <h:outputText value="Profile" />
                </f:facet>
                <center>
                    <h:outputText value="#{row.name}" />
                </center>
            </h:column>
            <h:column>
                <f:facet name="header">
                    <h:outputText value="Localizations" />
                </f:facet>
                    <h:dataTable id="uLoc" var="c" 
                    value="#{home.getLocByProfile(row.idProfile)}">
                        <h:column>
                            <h:outputText value="#{c}" />
                        </h:column>
                    </h:dataTable>
            </h:column>
            <h:column>
                <f:facet name="header">
                    <h:outputText value="Status" />
                </f:facet>
                <center>
                    <h:outputText value="#{row.active ? 'OK' : 'Inactive'}" />
                </center>
            </h:column>
        </h:dataTable>
    </rich:panel>
    

    【讨论】:

      猜你喜欢
      • 2023-01-28
      • 1970-01-01
      • 2020-08-11
      • 2013-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-10
      • 1970-01-01
      相关资源
      最近更新 更多