【问题标题】:How to escape f:selectItem itemLabel attribute如何转义 f:selectItem itemLabel 属性
【发布时间】:2013-01-09 15:27:32
【问题描述】:

如何转义f:SelectItem itemLabel 属性以便在标签中添加超链接?

使用以下代码,我能够逃脱h:outputText,但不能逃脱f:selectItem

            <h:outputText value="MyLink &lt;a href=&quot;http://google.com&quot; &gt;Google &lt;/a&gt;" escape="false"/>              
            <h:selectOneRadio id="p" value="#{bean.somevalue}" required="true" >
                <f:selectItem escape="false" escapeItem="false" itemLabel="One &lt;a href=&quot;http://google.com&quot; &gt;Google &lt;/a&gt;" itemValue="O" />
                <f:selectItem escape="false" escapeItem="false" itemLabel="Two &lt;a href=&quot;http://stackoverflow.com&quot; &gt;Stackoverflow&lt;/a&gt;" itemValue="T" />
            </h:selectOneRadio>

我想要如下图所示的东西

【问题讨论】:

    标签: jsf jsf-2


    【解决方案1】:

    这是 JSF 中的一个记录错误。 actual attribute 被命名为 itemEscaped,而不是 escapeItem (as incorrectly documented in VDL) 或 escape(Eclipse 自动完成功能确实出于某种未知原因自动提示,但实际上在 VDL 中完全不存在)。

    以下构造应该适合您(至少,它在 Mojarra 2.1.17 上适合我):

    <h:selectOneRadio>
        <f:selectItem itemEscaped="false" itemLabel="One &lt;a href=&quot;http://google.com&quot; &gt;Google &lt;/a&gt;" itemValue="O" />
        <f:selectItem itemEscaped="false" itemLabel="Two &lt;a href=&quot;http://stackoverflow.com&quot; &gt;Stackoverflow&lt;/a&gt;" itemValue="T" />
    </h:selectOneRadio>
    

    【讨论】:

    • 我刚刚修复了文档错误。迟到总比没有好:java.net/jira/browse/…
    • 对我来说它没有被转义,但它没有显示为链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 2013-05-23
    • 2011-12-01
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    相关资源
    最近更新 更多