1
我目前有一个任务来动态生成现在是静态的内容。问题是来自EL的sessionScope变量用于切换内容的呈现。由于sessionScope是一个Map,我真的不知道如何将其转换为在forEach循环中使用。将Java EE 7 EL映射转换为forEach循环的动态值
当前布局:
<p:outputPanel layout="block">
<p:commandLink id="testId">
<p:graphicImage value="#{request.contextPath}/images/test.jpg" />
<f:setPropertyActionListener value="#{!sessionScope.renderContentA}" target="#{sessionScope.renderContentA}" />
</p:commandLink>
<pe:tooltip for="testId" value="TestTooltip" />
</p:outputPanel>
<p:outputPanel layout="block">
<p:commandLink id="testId2">
<p:graphicImage value="#{request.contextPath}/images/test2.jpg" />
<f:setPropertyActionListener value="#{!sessionScope.renderContentB}" target="#{sessionScope.renderContentB}" />
</p:commandLink>
<pe:tooltip for="testId2" value="TestTooltip" />
</p:outputPanel>
,我需要转换为:
<c:forEach items="#{bean.items}" var="item">
<p:outputPanel layout="block">
<p:commandLink id="#{item.id}">
<p:graphicImage value="#{request.contextPath.concat(item.imageUrl)}" />
<f:setPropertyActionListener value="#{!SOMETHING-HERE}" target="#{SOMETHING-HERE}" />
</p:commandLink>
<pe:tooltip for="#{item.id}" value="TestTooltip" />
</p:outputPanel>
</c:forEach>
一个例子,其中它的使用(我需要调整藏汉):
<p:outputPanel autoUpdate="true" style="float: right;">
<p:commandLink rendered="#{!sessionScope.renderContentA}">
<h:outputText styleClass="ui-icon ui-icon-plus" />
<f:setPropertyActionListener value="#{!sessionScope.renderContentA}" target="#{sessionScope.renderContentA}" />
</p:commandLink>
<p:commandLink rendered="#{sessionScope.renderContentA}">
<h:outputText styleClass="ui-icon ui-icon-minus" />
<f:setPropertyActionListener value="#{!sessionScope.renderContentA}" target="#{sessionScope.renderContentA}" />
</p:commandLink>
</p:outputPanel>
我我一直在谷歌搜索了一段时间,但无法找到一个好的答案。我使用的是Glassfish 4,Java EE 7,EL 3和JSF 2.1.1-b04。如果我需要提供其他内容,请告诉我。