Bog*_*dan 2 java primefaces jsf-2
有条件地显示多个元素的最佳策略是什么(例如,依赖于bean值的字段列表)?
我想到的可能解决方案:
<c:if ... >条款.据我所知,使用JSTL和JSF是不鼓励的选项3似乎是最明智的,但我不知道用于包装这些字段的组件.它需要是一个不影响布局的组件......
我可以使用span作为包装器并设置CSS visible属性,但仍然会呈现字段,只是不可见.
有什么想法吗?
更新:
这是一些实际的布局代码.我试过两个<h:panelGroup>&<ui:fragment>.使用这些标签中的任何一个都会将我的所有字段都放在一个单独的字段中<td>,我承认,这是有意义的,因为我在我的文件中放置了一个顶级元素panelGrid.
唯一能按我想要的方式工作的是上面列表中的#2.
<h:panelGrid columns="2">
<!-- fields if person -->
<ui:fragment rendered="#{createEntity.entityType eq 'fizica'}">
<h:outputLabel value="Prenume: " />
<h:inputText value="#{createEntity.person.firstName}" />
<h:outputLabel value="Nume familie: " />
<h:inputText value="#{createEntity.person.familyName}" />
<h:outputLabel value="CNP: " />
<h:inputText value="#{createEntity.person.cnp}" />
<h:outputLabel value="Date carte identitate: " />
<h:inputText value="#{createEntity.person.idCardInfo}" />
<h:outputLabel value="Cetatenie: " />
<h:inputText value="#{createEntity.person.country}" />
</ui:fragment>
<!-- fields for company -->
<ui:fragment rendered="#{createEntity.entityType eq 'juridica'}">
<h:outputLabel value="Denumire firma" />
<h:inputText value="#{createEntity.company.name}" />
<h:outputLabel value="CUI" />
<h:inputText value="#{createEntity.company.cui}" />
<h:outputLabel value="Registrul Comertului" />
<h:inputText value="#{createEntity.company.regCommerceNo}" />
</ui:fragment>
</h:panelGrid>
Run Code Online (Sandbox Code Playgroud)
渲染是显示(或不显示)组件的推荐方式.
如果您可以将它们组合在一起,那么设置容器的呈现属性是完全有效的.我会优先考虑在每个单独的组件上设置呈现的属性.
唯一的缺点是,如果显示是动态的(您更改了支持bean值),并且您需要重新显示容器,则它不存在.您需要将容器包装在另一个容器中,然后再使用reRender.
| 归档时间: |
|
| 查看次数: |
12364 次 |
| 最近记录: |