重复< f:verbatim>在< ui:repeat>中 [英] Iterate <f:verbatim> within <ui:repeat>

查看:95
本文介绍了重复< f:verbatim>在< ui:repeat>中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个@ViewScoped bean,其中的List<String>包含纯HTML.我想遍历此列表并输出纯HTML:

I have a @ViewScoped bean with a List<String> containing plain HTML. I want to iterate over this list and output plain html:

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

上面的代码片段效果很好,但是刷新页面时,将调用bean costrunctor.已知此问题/错误: JSTL c: forEach导致@ViewScoped bean在每个请求上调用@PostConstruct

That snippet above works well but when the page is refreshed the bean costrunctor is recalled. This issue/bug is known: JSTL c:forEach causes @ViewScoped bean to invoke @PostConstruct on every request

因此建议将<c:forEach>替换为<ui:repeat>.

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

但这不起作用.我有一个空白页.我尝试了<h:dataTable><a4j:repeat><rich:dataTable>,但无济于事.

But that doesn't work. I have a blank page. I tried <h:dataTable>, <a4j:repeat> and <rich:dataTable> but nothing to do.

有解决方案吗?

推荐答案

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

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

<f:verbatim>是一个面向JSP的旧标签,旨在将纯HTML嵌入JSF 1.0/1.1中的JSF组件之间.没有它,所有纯HTML都将在JSF组件树之前 呈现.这种不直观的行为在JSF 1.2中得到了修复,这使得该标签变得多余了.在Facelets中,它也是多余的;在Facelets 2.0中(对于JSF 2.0),它甚至已弃用.另请参见标记文档的介绍性文本.不要使用它.如果要呈现未转义的HTML,请按照上述示例中的建议使用<h:outputText escape="false">.如果要有条件地呈现内联HTML片段,请改用<h:panelGroup><ui:fragment>.

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. Without it, all the plain HTML would otherwise be rendered before the JSF component tree. This unintuitive behaviour was fixed in JSF 1.2 which made the tag superfluous. In Facelets it's also superfluous and in Facelets 2.0 (for JSF 2.0) it's even deprecated. 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. If you want to render pieces of inline HTML conditionally, rather use <h:panelGroup> or <ui:fragment> instead.

这篇关于重复&lt; f:verbatim&gt;在&lt; ui:repeat&gt;中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆