【发布时间】:2014-01-09 11:47:11
【问题描述】:
我需要编写一个放在<h:outputLink>...</h:outputLink> 标签内并输出<f:param ... /> 标签的复合组件。生成的<f:param /> 标记的来源是由过滤器设置的请求属性,其中包含为属性name 和value 提供值的对象列表。
现在有两个问题:
-
<f:param />标签不影响周围<h:outputLink>生成的URL -
<c:forEach>不会遍历从请求属性中检索到的列表。
总的来说,整个组件的行为有点奇怪,因为我可以访问列表的特定元素并输出它的值。但是,一旦涉及到<c:forEach>,循环就不会输出任何内容。
组件目前如下所示:
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:cc="http://xmlns.jcp.org/jsf/composite"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<!-- INTERFACE -->
<cc:interface>
</cc:interface>
<!-- IMPLEMENTATION -->
<cc:implementation>
<!-- works, outputs e.g. 'confirmationData' -->
#{activeContentThreadList[0].name}
<!-- does not work, link URL is unaffected -->
<f:param name="#{activeContentThreadList[0].displayName}"
value="#{activeContentThreadList[0].token}" />
<!-- works, outputs e.g. '[some.package.class@7951a73c]' -->
<h:outputText value="#{activeContentThreadList}" />
<!-- does not work, nothing is outputted -->
<c:forEach items="#{activeContentThreadList}" var="asd">
<h:outputText value="#{asd.name}" />
<h:outputText value="test in loop" />
</c:forEach>
</cc:implementation>
</f:view>
组件使用如下:
<h:outputLink value="#{request.contextPath}/confirmation/fields/ordersearch.xhtml" styleClass="ext">
<cst:activeThreads />
</h:outputLink>
我的问题:
- 为什么我可以访问特定的列表项,但
<c:forEach>却什么也没做? - 为什么链接 URL 至少不受单个
<f:param>标记的影响? - 是否甚至可以将
<f:param>标签从内部复合组件输出到周围的链接?
【问题讨论】:
-
嘿,marius,希望您已经解决了所描述的问题。如果是这样,请确认下面的答案。 :-)
-
我当然会,刚回到办公室。我试过
<ui:repeat>并没有改变任何东西。所以不可能生成影响周围链接的<f:param>标签。我最终只使用了一个带有静态参数名称的<f:param>。
标签: jsf jsf-2 jstl facelets composite-component