开发者

How to show a bold message with Seam 2 StatusMessages?

开发者 https://www.devze.com 2023-02-08 12:31 出处:网络
I have a seam component where I put a message using standard seam annotation: @In private StatusMessages statusMessages;

I have a seam component where I put a message using standard seam annotation:

@In
private StatusMessages statusMessages;

public void myMethod()
{
  statusMessages.add("Welcome, #{user.getName()}, after confirmation you will be able to log in.");
}

and than in the xthml page to show this message:

<h:messages id="mensagensHome" globalOnly="true" styleClass="message"
            errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"
            rendered="#{showGlobalMessages != 'false'}" />

This is working perfectly, but I have a requirement where the name should be Bold. Than I have already tryed placing standard html tags in my message like:

 statusMessages.add("Welcome, <b> #{user.getName()} </b>, after confirmation you will be able to log in.");
开发者_C百科

But than it shows the tags on the page and does not turn the name bold.

I have also tried using unicode escape character to render the html tags, but again no success.

Is it possible to use standard html tags from code looking forward to format messages in Seam?

Tx in advance.


Actually you can't, unlike h:outputText h:messages don't have an escape property where you would be able to do escape="false".

In the link bellow you can find a sample on how to extend h:messages, actually it's not exactly h:messages that is extended but the end result is the same. So you can set escape="false" in h:messages and have the browser parse html tags.

http://balusc.blogspot.com/2010/07/using-html-in-jsf-messages.html

Be careful if you display something that the user inserted because this is is prone to html injection.

Note: The link is not mine, but it did work for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消