通过 <ui:repeat> 动态填充 selectOneMenu 中的选项
Dynamically populate options in a selectOneMenu by <ui:repeat>
我正在尝试根据 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>
.
A <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>
我正在尝试根据 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>
.
A <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>