Adriano
Adriano

Reputation: 64

Struts 2 Validation message with HTML code inside

I'm trying to create a Struts2 Validation Message with some HTML code inside.

For example:

<field-validator type="regex">
    <param name="expression">
        <![CDATA[^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(\.[0-9]{1,2})?$]]>
    </param>
    <message>
      <b>${Price}</b> field for <b>${fundDescription}</b> and 
         <b>${currencyDescription}</b> must be a number and in the correct format
    </message>
</field-validator>

I know that <b>${Price}</b> and &lt;b&gt;${Price}&lt;/b&gt; don't work. Is there any way to do that?

I'm not including my entire code because it's irrelevant.

Upvotes: 1

Views: 114

Answers (1)

Aleksandr M
Aleksandr M

Reputation: 24396

The error message is escaped (doesn't show html) for security reasons. If you are using xhtml theme (which is default) the escaping happens in FreeMarker template.

You can create your own template and display error as it is or you can use different theme (e.g. simple) and show errors using <s:fielderror> tag with escape attribute set to false.

BUT be aware that not escaping html content you don't totally control can lead to security issues.

Upvotes: 2

Related Questions