将HTML添加到<h:messages />

6

我将使用 Twitter Bootstrap。

警告 HTML 代码如下:

<div class="alert alert-block">
  <a class="close" data-dismiss="alert" href="#">×</a>
  <h4 class="alert-heading">Warning!</h4>
  Best check yo self, you're not...
</div>

我使用<h:messages />来显示我的表单错误、信息和警告消息,如下所示:
<h:messages errorClass="alert alert-error" infoClass="alert alert-info" warnClass="alert alert-warning"/>

颜色和圆角都可以,但我需要添加关闭链接:
<a class="close" data-dismiss="alert" href="#">×</a>

我该如何使用 <h:messages/> 标签呢? 编辑 如果需要更好的理解,这里是 Twitter Bootstrap 的警告样式链接: http://twitter.github.com/bootstrap/components.html#alerts
3个回答

7

I guess the usual way you add messages ...

FacesContext context = 
FacesContext.getCurrentInstance(); 
context.addMessage(null, new FacesMessage(your message goes here...  

消息应从服务器端添加...例如String myMessage = "这里是文本/ HTML代码..."

请参阅BalusC的此文章

在JSF消息中使用HTML


好的...我将开始这样做,我会在我的html文件中这样写:<h:inputText requiredMessage="O campo Pesquisa é obrigatório" id="pesquisa" styleClass="input-xxlarge search-query" required="true"/>,并在我的form顶部添加一个<h:messages />,谢谢。 - user745235
我还没有尝试过这个解决方案,但它看起来像是一个...不用谢。 - Daniel

3
只需使用omnifaces o:messages,问题将得到解决。
例如< o:messages escape =“false”/ >

0

另一种解决方案是

<div class="alert alert-danger alert-dismissible fade in" role="alert" jsf:rendered="#{not empty facesContext.getMessageList('InputPassword')}">
     <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
  <strong>Error </strong>  <h:message for="InputPassword" /> 
                                    </div>

这是针对JSF 2.2的,但您可以调整为先前版本的JSF。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接