我需要使用outputText
呈現換行符,以便我可以利用歸因的rendered
。我試圖如何使用outputText顯示換行符?
<h:outputText value="<br/>" escape="false" />
,但它產生的異常
The value of attribute "value" associated with an element type "null" must not contain the '<' character.
我需要使用outputText
呈現換行符,以便我可以利用歸因的rendered
。我試圖如何使用outputText顯示換行符?
<h:outputText value="<br/>" escape="false" />
,但它產生的異常
The value of attribute "value" associated with an element type "null" must not contain the '<' character.
由於Facelets在語法上無效,因此這確實無效。您需要手動轉義XML特殊字符,如<
,>
等。
<h:outputText value="<br/>" escape="false" />
但是,您可以只發出模板文本<br/>
,而不需要一個<h:outputText>
。
<br/>
要有條件地渲染它,請將其包裝在例如<ui:fragment>
中。
<ui:fragment rendered="#{bean.rendered}"><br /></ui:fragment>
A <h:panelGroup>
也是有效的,因爲它不會向HTML發送任何內容。
<h:panelGroup rendered="#{bean.rendered}"><br /></h:panelGroup>
你可以嘗試把"<br />"
資源包內,然後從那個資源包的價值。
JSF頁面
<h:outputText value="#{car.crg}" escape="false" style="white-space: pre-wrap;word-wrap: break-word; " />
逃生應false
和如下
public String getCrg() {
return crg.replace("<br/>", "<br />");
//return crg;
}
你會怎麼做時,在動態添加'HtmlOutputText'寫豆
Getter
方法託管bean?我試過'HtmlOutputText linebreak = new HtmlOutputText(); lineBreak.setValue(「< br/>」和「」);'(顯然不是同時那樣),但都沒有工作,他們只輸出輸入的文本,而不是休息 – Austin 2012-08-15 20:11:59
@Austin:顯然你忘記了調用' setEscape(假)'。 – BalusC 2012-08-15 20:15:22
確定你不需要任何新書嗎? =) – Austin 2012-08-15 20:35:12