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。如果我需要提供其他內容,請告訴我。