1

I have a method at Spring controller which returns HTML code. How can I inlude this HTML code in DetailsDialog? By the way this method returns HTML codes as Byte Array.

<p:dialog id="DetailsDialog" header="Details" widgetVar="DetailsDialogWid">
    <!--HTML PAGE-->
</p:dialog>

1 Answer 1

4

You can simply include your HTML content with an h:outputText, but you will need to change your output content in String before.

Bean code :

public String getHtmlContent()
{
    return String(getByteArrayHtmlContent(), CHARACTER_ENCODING_OF_HTML);
}

Note that you must generally specify the character encoding of the byte array to correctly convert it to a string. CHARACTER_ENCODING_OF_HTML might be "US-ASCII", "UTF-8", "ISO-8859-1" etc. depending on what the byte array contains.

View code :

<p:dialog id="DetailsDialog" header="Details" widgetVar="DetailsDialogWid">
    <h:outputText value="#{yourBean.htmlContent}" escape="false" />
</p:dialog>

Note the escape="false" that prevent conversion to HTML entities.

More info : JSF outputText example

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

1 Comment

Using new String(byte[]) is almost always wrong, because it uses the default character encoding, which might be anything. I took the liberty of editing that into the answer.

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.