简体   繁体   English

重复 <f:verbatim> 内 <ui:repeat>

[英]Iterate <f:verbatim> within <ui:repeat>

I have a @ViewScoped bean with a List<String> containing plain HTML. 我有一个@ViewScoped bean,其中的List<String>包含纯HTML。 I want to iterate over this list and output plain html: 我想遍历此列表并输出纯HTML:

<c:forEach items="#{bean.list}" var="html">
  <f:verbatim>#{html}</f:verbatim>
</c:forEach>

That snippet above works well but when the page is refreshed the bean costrunctor is recalled. 上面的代码片段效果很好,但是刷新页面时,将调用bean costrunctor。 This issue/bug is known: JSTL c:forEach causes @ViewScoped bean to invoke @PostConstruct on every request 已知此问题/错误: JSTL c:forEach导致@ViewScoped bean在每个请求上调用@PostConstruct

So the suggestion is to replace <c:forEach> with <ui:repeat> . 因此建议将<c:forEach>替换为<ui:repeat>

<ui:repeat value="#{bean.list}" var="html">
  <f:verbatim>#{html}</f:verbatim>
</ui:repeat>

But that doesn't work. 但这是行不通的。 I have a blank page. 我有空白页。 I tried <h:dataTable> , <a4j:repeat> and <rich:dataTable> but nothing to do. 我尝试了<h:dataTable><a4j:repeat><rich:dataTable>但没有任何反应。

Any solutions? 有什么办法吗?

Use <h:outputText escape="false"> instead. 请改用<h:outputText escape="false">

<ui:repeat value="#{bean.list}" var="html">
    <h:outputText value="#{html}" escape="false" />
</ui:repeat>

The <f:verbatim> is an old JSP-oriented tag which was intented to be able to embed plain HTML among JSF components in JSF 1.0/1.1. <f:verbatim>是一个面向JSP的旧标签,旨在将纯HTML嵌入JSF 1.0 / 1.1中的JSF组件之间。 Without it, all the plain HTML would otherwise be rendered before the JSF component tree. 没有它,所有纯HTML都将在JSF组件树之前呈现。 This unintuitive behaviour was fixed in JSF 1.2 which made the tag superfluous. 这种不直观的行为在JSF 1.2中得到了解决,这使得该标签变得多余了。 In Facelets it's also superfluous and in Facelets 2.0 (for JSF 2.0) it's even deprecated . 在Facelets中,它也是多余的;在Facelets 2.0中(对于JSF 2.0),它甚至已被弃用 See also the introductory text of the tag documentation . 另请参见标签文档的介绍性文本。 Don't use it. 不要使用它。 If you want to render unescaped HTML, rather use the <h:outputText escape="false"> as suggested in the above example. 如果要呈现未转义的HTML,请按照上述示例中的建议使用<h:outputText escape="false"> If you want to render pieces of inline HTML conditionally, rather use <h:panelGroup> or <ui:fragment> instead. 如果要有条件地呈现内联HTML片段,请改用<h:panelGroup><ui:fragment>

Why not to use ViewScoped datamodel? 为什么不使用ViewScoped数据模型?

in JEE5 (JSF 1.2) - could be seam-managed @Factory("bean.list") List<> produceList()... It will be view-scoped (actually page-scoped). 在JEE5(JSF 1.2)中-可以由接缝管理@Factory("bean.list") List<> produceList()...将在视图范围内(实际上是页面范围)。

and in JEE6 (JSF 2.0) you can use the same pattern with CDI. 在JEE6(JSF 2.0)中,可以对CDI使用相同的模式。

Or you can implement the same lifecycle for your list and create own solution. 或者,您可以为列表实现相同的生命周期并创建自己的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM