Mat*_*ias 1 user-interface jsf primefaces
我正在尝试根据 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>
Run Code Online (Sandbox Code Playgroud)
当我访问该页面时,它显示 [1, 2, 3]123 和一个空的 selectOneMenu。我本来希望 selectOneMenu 也包含这些选择。迭代显然适用于上述情况,所以我不知道为什么它不显示菜单中的选项。我究竟做错了什么?
这<ui:repeat>
是一个 UI 组件,<f:selectItem>
而是一个标记处理程序(如 JSTL)。标签处理程序在视图构建期间运行,然后在视图渲染期间运行的 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>
Run Code Online (Sandbox Code Playgroud)