Turgut Dsfadfa
Turgut Dsfadfa

Reputation: 795

How to include HTML content programmatically?

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>

Upvotes: 1

Views: 318

Answers (1)

Alexandre Lavoie
Alexandre Lavoie

Reputation: 8771

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

Upvotes: 4

Related Questions