显示嵌套数据表而不重复原始数据
Show nested datatable without repeating original data
我想显示数据库中的数据但不能重复相同的配置文件,只需在现有配置文件中添加一个位置即可。有了上面的例子就清楚了:
+-------------------+---------------+---------------+
| PROFILE | LOCATION | STATUS |
+-------------------+---------------+---------------+
+-------------------+---------------+---------------+
| Admin | Chief | OK |
+-------------------+---------------+---------------+
| Director | Supervision | OK |
+-------------------+---------------+---------------+
| Secretary | Supervision | OK |
+-------------------+---------------+---------------+
| | Admin | OK |
| | Chief | OK |
| Chief-accessor | Director | OK |
| | Secretary | OK |
| | Supervision | OK |
+-------------------+---------------+---------------+
这段代码是我的数据table,只能重复,不能分组:
<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
我已经尝试在 Whosebug 中遵循一些答案,这些答案说将一个数据 table 放入另一个数据 table,但我可以重复所有没有组配置文件的位置,例如:
+-------------------+---------------+---------------+
| 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...
我的疑问是我正在做的通用查询,所以 table 中的内容重复。有人知道这个操作吗?
相关问题:
- Nested datatable in JSF 2.0
- JSF: Empty nested dataTable
- JSF, datatable in datatable
因为我无法按照他们的方式来做到这一点 return 同一配置文件的所有位置并且只使用一个查询,我决定做不同的事情,我想到了使用两个查询,一个用于所有没有重复配置文件 (select distinct ...
) 并且根据配置文件每个位置一个。才意识到(如果我错了请纠正我)属性 h:datatable
按列而不是行呈现。因此,在某种程度上,第一个配置文件列 return 全部没有重复配置文件,但是如果位置将出现的单元格属于给定配置文件,则每个单元格中的位置都相同显示所有用户位置而没有区别.就在那时我意识到我非常专注于关注用户配置文件的位置。
运行 select distinct
配置文件并创建了一种方法来 return 在创建 table 时配置文件的位置。正如报题,一个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>
我想显示数据库中的数据但不能重复相同的配置文件,只需在现有配置文件中添加一个位置即可。有了上面的例子就清楚了:
+-------------------+---------------+---------------+
| PROFILE | LOCATION | STATUS |
+-------------------+---------------+---------------+
+-------------------+---------------+---------------+
| Admin | Chief | OK |
+-------------------+---------------+---------------+
| Director | Supervision | OK |
+-------------------+---------------+---------------+
| Secretary | Supervision | OK |
+-------------------+---------------+---------------+
| | Admin | OK |
| | Chief | OK |
| Chief-accessor | Director | OK |
| | Secretary | OK |
| | Supervision | OK |
+-------------------+---------------+---------------+
这段代码是我的数据table,只能重复,不能分组:
<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
我已经尝试在 Whosebug 中遵循一些答案,这些答案说将一个数据 table 放入另一个数据 table,但我可以重复所有没有组配置文件的位置,例如:
+-------------------+---------------+---------------+
| 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...
我的疑问是我正在做的通用查询,所以 table 中的内容重复。有人知道这个操作吗?
相关问题:
- Nested datatable in JSF 2.0
- JSF: Empty nested dataTable
- JSF, datatable in datatable
因为我无法按照他们的方式来做到这一点 return 同一配置文件的所有位置并且只使用一个查询,我决定做不同的事情,我想到了使用两个查询,一个用于所有没有重复配置文件 (select distinct ...
) 并且根据配置文件每个位置一个。才意识到(如果我错了请纠正我)属性 h:datatable
按列而不是行呈现。因此,在某种程度上,第一个配置文件列 return 全部没有重复配置文件,但是如果位置将出现的单元格属于给定配置文件,则每个单元格中的位置都相同显示所有用户位置而没有区别.就在那时我意识到我非常专注于关注用户配置文件的位置。
运行 select distinct
配置文件并创建了一种方法来 return 在创建 table 时配置文件的位置。正如报题,一个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>