我创建了一个相当复杂的嵌套dataGrid / selectManyMenu构造,以便在多个数据库表上进行多方面选择,每个数据库表都由自己的视图模型表示。基本思想是创建一个完全动态的构面面板,以交互方式过滤多个dataTable中的搜索结果。
环境
观察
f:selectItems
中的p:selectManyMenu
在filterPanel中正确显示所有 viewModel / facetContainer组合#{basicSearchView.viewModels}
中的第一个viewModel中选择项目,则一切正常,因此#{facetContainer.selectedFacets}
会更新相应的facetContainer #{basicSearchView.viewModels}
中的第二个viewModel中选择了相应facetContainer的#{facetContainer.selectedFacets}
未更新用户界面草图
filterPanel
---------------------------------------------------------------
| ------------------- ------------------- ------------------- |
| | ViewModel 1 | | ViewModel 2 | | ViewModel n | |
| |-----------------| |-----------------| |-----------------| |
| | FacetField 1.1 | | FacetField 2.1 | | FacetField n.1 | |
| |-----------------| |-----------------| |-----------------| |
| | Facet (count) | | Facet (count) | | Facet (count) | |
| |-----------------| |-----------------| |-----------------| |
| | Facet (count) | | Facet (count) | | Facet (count) | |
| |-----------------| |-----------------| |-----------------| |
| | FacetField 1.2 | | FacetField 2.2 | | FacetField n.2 | |
| |-----------------| |-----------------| |-----------------| |
| | Facet (count) | | Facet (count) | | Facet (count) | |
| |-----------------| |-----------------| |-----------------| |
| | Facet (count) | | Facet (count) | | Facet (count) | |
| |-----------------| |-----------------| |-----------------| |
| | ... | | ... | | ... | |
| |-----------------| |-----------------| |-----------------| |
相关的XHTML部分
<p:outputPanel id="filterPanel">
<p:dataGrid id="typeGrid" var="viewModel" value="#{basicSearchView.viewModels}" rows="1"
columns="#{basicSearchView.viewModels.size()}" style="border:none;" styleClass="lh-dgrid-column">
<p:column>
<p:panel id="facetPanel" header="#{viewModel.modelName}">
<p:dataGrid id="facetGrid" var="facetContainer" value="#{viewModel.facetContainers}" rows="#{viewModel.facetContainers.size()}"
columns="1" style="border:none;" emptyMessage="No facets found">
<h:outputText value="#{facetContainer.fieldHeader}" styleClass="FontBold Fs14 hardblue"/>
<p:selectManyMenu id="facetSelectMenu" value="#{facetContainer.selectedFacets}" converter="#{facetBeanConverter}"
showCheckbox="true">
<f:selectItems value="#{facetContainer.availableFacets}" var="facet" itemLabel="#{facet.facetName} (#{facet.facetCount})"
itemValue="#{facet}" />
<p:ajax update="contentForm:tabView contentForm:overviewMap"/>
</p:selectManyMenu>
</p:dataGrid>
</p:panel>
</p:column>
</p:dataGrid>
</p:outputPanel>
嵌套类型层次结构
@ManagedBean
@ViewScoped
class BasicSearchView {
List<ViewModel> viewModels;
// Add managed viewModels to list
}
@ManagedBean
@ViewScoped
class ViewModel {
//...
List<FacetContainer> facetContainers;
}
// POJO
class FacetContainer {
//...
String fieldHeader;
List<FacetBean> availableFacets;
List<FacetBean> selectedFacets;
}
// POJO
class FacetBean {
//...
String facetName;
String facetCount;
}
希望这能恰当地描述问题......