f中的筛选值:选择JSF/Primefaces中的项目
我在JSF+JPA应用程序中有双边的一对多关系。我只想在视图中列出列表中已过滤的项目。在控制器中执行此操作很困难,是否可以像下面那样进行过滤f中的筛选值:选择JSF/Primefaces中的项目,jsf,jpa,primefaces,Jsf,Jpa,Primefaces,我在JSF+JPA应用程序中有双边的一对多关系。我只想在视图中列出列表中已过滤的项目。在控制器中执行此操作很困难,是否可以像下面那样进行过滤 <p:selectOneListbox id="cmbField" value="#{investigationItemController.current}" > <f:selectItems value="#{investigationItemController.currentInvestigation.reportIte
<p:selectOneListbox id="cmbField" value="#{investigationItemController.current}" >
<f:selectItems value="#{investigationItemController.currentInvestigation.reportItems}" var="ri" itemLabel="#{ri.name}" itemValue="#{ri}" itemRendered="#{ri.retired ne true and ri.ixItemType eq 'Value'}" />
</p:selectOneListbox>
控制器类的重要代码集如下所示
@ManagedBean
@SessionScoped
public final class InvestigationItemController implements Serializable {
private static final long serialVersionUID = 1L;
@EJB
private InvestigationItemFacade ejbFacade;
private InvestigationItem current;
private Investigation currentInvestigation;
// Other code goes here
}
在JSF/Primefaces中使用f:selectItem或f:selectItems时,如何过滤项目
(我将解释我的真实情况,为什么我迫切需要这个功能
我正在开发一个医疗应用程序,术语令人困惑。测试或调查(如全血计数或尿液完整报告)可能有几个属性。测试被表示为一个调查实体。测试由一个或多个字段组成(如血红蛋白、FBC的白细胞计数和UFR的颜色、外观)。它表示为调查项目。单个调查项目可能有一个可能值列表,其中一个在不同情况下被选择。它们被标识为调查项目值。因此,一个调查项目有一个调查项目值列表。但是,例如,一些调查项目值可能是字符串类型,而另一些是数字类型。用户在设计一个特定类型的新调查时需要选择一个调查项目值。因此,需要在视图中进行筛选。)PrimeFaces
实际上隐藏了
,并生成了一个
,这允许您更自由地进行CSS样式设置
您只需使用itemsabled
属性,然后使用CSS将禁用的项目设置为display:none
<p:selectOneListbox ...>
<f:selectItems value="#{investigationItemController.currentInvestigation.reportItems}"
var="ri" itemLabel="#{ri.name}" itemValue="#{ri}"
itemDisabled="#{not ri.retired and ri.ixItemType eq 'Value'}" />
</p:selectOneListbox>
关于您尝试使用
失败的原因;它失败,因为
是在视图生成时计算的,而不是在视图渲染时计算的。但是,
在视图渲染期间运行。在此期间,
在组件树中不可用。它应该在视图构建期间附加到UISelectOne
/UISelectMany
父级
JSTL在视图构建期间运行,如
,因此,对循环使用JSTL
,对条件构建(不渲染!)使用JSTL也应该这样做:
<p:selectOneListbox ...>
<c:forEach items="#{investigationItemController.currentInvestigation.reportItems}" var="ri">
<c:if test="#{not ri.retired and ri.ixItemType eq 'Value'}">
<f:selectItem itemLabel="#{ri.name}" itemValue="#{ri}" />
</c:if>
</c:forEach>
</p:selectOneListbox>
您只需要考虑,在使用早于2.1.18的Mojarra版本时,这会破坏视图范围的bean
另见:
实际上隐藏了
,并生成了一个
,允许您更自由地进行CSS样式设置
您只需使用itemsabled
属性,然后使用CSS将禁用的项目设置为display:none
<p:selectOneListbox ...>
<f:selectItems value="#{investigationItemController.currentInvestigation.reportItems}"
var="ri" itemLabel="#{ri.name}" itemValue="#{ri}"
itemDisabled="#{not ri.retired and ri.ixItemType eq 'Value'}" />
</p:selectOneListbox>
关于您尝试使用
失败的原因;它失败,因为
是在视图生成时计算的,而不是在视图渲染时计算的。但是,
在视图渲染期间运行。在此期间,
在组件树中不可用。它应该在视图构建期间附加到UISelectOne
/UISelectMany
父级
JSTL在视图构建期间运行,如
,因此,对循环使用JSTL
,对条件构建(不渲染!)使用JSTL也应该这样做:
<p:selectOneListbox ...>
<c:forEach items="#{investigationItemController.currentInvestigation.reportItems}" var="ri">
<c:if test="#{not ri.retired and ri.ixItemType eq 'Value'}">
<f:selectItem itemLabel="#{ri.name}" itemValue="#{ri}" />
</c:if>
</c:forEach>
</p:selectOneListbox>
您只需要考虑,在使用早于2.1.18的Mojarra版本时,这会破坏视图范围的bean
另见:
<p:selectOneListbox ...>
<c:forEach items="#{investigationItemController.currentInvestigation.reportItems}" var="ri">
<c:if test="#{not ri.retired and ri.ixItemType eq 'Value'}">
<f:selectItem itemLabel="#{ri.name}" itemValue="#{ri}" />
</c:if>
</c:forEach>
</p:selectOneListbox>