【问题标题】:Trying to add new line characters while using JSF h:outputText and Managed Beans尝试在使用 JSF h:outputText 和托管 Bean 时添加换行符
【发布时间】:2014-10-01 06:11:54
【问题描述】:

我这里有一个 h:outputText

<h:outputText id="properties" value="#myBean.output}" />

然后我有一个按钮,它调用一个函数来更新“输出”中的值,这是一个字符串,其中基本上包含一个文本文档(即多行)

<h:panelGrid columns="2" >
    <p:outputLabel value="Display Output."/>
    <p:commandButton value="submit" action="#{myBean.updateOutput}">
        <f:ajax render="properties" />
    </p:commandButton>                  
</h:panelGrid>

但是,我希望它在输出中具有 \n 或类似的输出。

这是我将返回的示例:

Line1\nLine2\nLine3

但是这只是像这样打印到屏幕上:

Text1 Text2 Text3

将其更改为 br/ 它不会做任何事情,只会导致它放置文字文本 br/ 而不是上面的空格。

我是 JSF 的新手,我只是想不通。我确实寻找了答案,但没有一个对我有用。非常感谢您的帮助。

【问题讨论】:

    标签: jsf text javabeans managed-bean


    【解决方案1】:

    h:outputText 上的escape 属性设置为false

    Escape 是标志,表示 HTML 中的敏感字符和 XML 标记必须进行转义。此标志默认设置为“true”。

    【讨论】:

    • 此外,escape="false" 不能与 \n 一起使用,但可以与 &lt;br/&gt; 一起使用。
    猜你喜欢
    • 2012-02-03
    • 2012-10-13
    • 1970-01-01
    • 2013-08-20
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    相关资源
    最近更新 更多