我正在尝试使用内容取决于GUI中其他选项的一些选项,在primefaces中填充一些下拉菜单。这是我正在尝试做的简化示例:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core" >
<h:head>
<title>Test</title>
</h:head>
<h:body>
<h:form>
<c:set var="options" value="#{['1','2','3']}" />
<c:set var="currentValue" value="#{3}" />
<h:outputText value="${options}" />
<ui:repeat var="r" value="#{options}">
<h:outputText value="#{r}" />
</ui:repeat>
<c:set var="currentValue" value="#{currentValue}" />
<p:selectOneMenu id="selectValue"
value="${currentValue}"
class="pFieldSet_Template_Input200 r10">
<p:ajax event="change" />
<ui:repeat var="r" value="#{options}">
<f:selectItem itemLabel="Choice #{r} (20180101)" itemValue="#{r}" />
</ui:repeat>
</p:selectOneMenu>
</h:form>
</h:body>
</html>
当我访问该页面时,它显示[1,2,3] 123和一个空的selectOneMenu。我本来期望selectOneMenu也包含选择。迭代在上面的情况下很常见,所以我不知道为什么它不显示菜单中的选项。我究竟做错了什么?
<ui:repeat>
是一个UI组件,而<f:selectItem>
是一个标签处理程序(如JSTL)。 Taghandlers在视图构建时运行之前在视图渲染时运行的UI组件之前运行。因此,在<ui:repeat>
运行的那一刻,没有任何<f:selectItem>
的手段。
一个<c:forEach>
,也是一个标记处理程序,可以工作:
<p:selectOneMenu id="selectValue"
value="${currentValue}"
class="pFieldSet_Template_Input200 r10">
<p:ajax event="change" />
<c:forEach items="#{options}" var="r">
<f:selectItem itemLabel="Choice #{r} (20180101)" itemValue="#{r}" />
</c:forEach>
</p:selectOneMenu>