问题描述
我将其发布到PrimeFaces用户论坛上,但是我认为他们太忙了,无法研究它,所以我想我可以在这里尝试.
I posted this to the PrimeFaces user forum but I think they are too busy to look into it, so I thought I would try here.
我在其中包含标记的服务器端字符串,所以当我要呈现它时,我可以这样做:
I have server-side string that has markup in it, so when I want it rendered I do this:
<p:panel>
<f:verbatim>
#{daBean.markedUpString}
</f:verbatim>
</p:panel>
这很好用,但是如果 p:dataTable 中使用了相同的标签,则不管该标签是否带有 p:panel .呈现的是一个 div class ="ui-dt-c" 元素,其中没有任何内容.为了进行测试,如果我删除了 f:verbatim 标记,则标记后的文本将被转义并呈现.
This works fine, but not if the same tag is used inside a p:dataTable -- either with or without the p:panel enclosure. What gets rendered is a div class="ui-dt-c" element with nothing in it. To test, if I take out the f:verbatim tag the marked-up text gets escaped and rendered.
我不知道是否应该将其视为错误,但是没有人知道解决方法吗?这是PrimeFaces 3.0.M3的版本.
I don't know if this should be considered a bug or not, but does anyone know of a work-around for this? This is with PrimeFaces 3.0.M3.
推荐答案
<f:verbatim>
标记旨在容纳纯文本文本/HTML,而不是JSF组件或EL表达式.当无法在JSF组件之间内联纯文本/HTML时,该标记是JSF 1.0/1.1时代的遗留物.该标签在JSF2中已弃用.您不再需要它.
The <f:verbatim>
tag is intented to hold plain text/HTML, not JSF components nor EL expressions. The tag is a leftover from JSF 1.0/1.1 ages when it was not possible to inline plain text/HTML between JSF components. The tag is deprecated in JSF2. You do not need it anymore.
因此,您的具体功能要求是显示未转义的托管Bean中的一些HTML字符串.为此,您应该将<h:outputText>
与escape="false"
一起使用.
Your concrete functional requirement is thus displaying some HTML string from a managed bean unescaped. For that you should use <h:outputText>
with escape="false"
.
<h:outputText value="#{daBean.markedUpString}" escape="false" />
另请参见:
- f:verbatim内部的字母在提交表单之前被调用
- Java的主要缺点是什么Server Faces 2.0?
- Getters inside f:verbatim called before form submission
- JSF/Facelets: why is it not a good idea to mix JSF/Facelets with HTML tags?
- What are the main disadvantages of Java Server Faces 2.0?
See also:
这篇关于在dataTable中时,f:verbatim标记停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!