2

Is it possible to get HTML code that is inside a bean variable and print it in the Facelets file as HTML code and not as text?

Example:

myBean.java

public String getMyHtmlCode(){
    return "<span class="little">Internet</span> 100Mb <span class="little">+television</span>"
}

file.xhtml

 <h2>#{myBean.myHtmlCode}</h2>

But in the navigator appears

<span class="little">Internet</span> 100Mb <span class="little">+television</span>

And is not interpreted as html.

Any idea?

3

1 Answer 1

2

In BalusC words from his comment:

(You) should just disable the default escaping of the text

<h2>
    <h:outputText value="#{myBean.myHtmlCode}" escape="false" />
</h2>

Just note that this code is prone to XSS attacks.

Sign up to request clarification or add additional context in comments.

1 Comment

No, he should not escape the text. He should just disable the default escaping of the text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.