【问题标题】:Add HTML to <h:messages />将 HTML 添加到 <h:messages />
【发布时间】:2012-05-12 23:31:31
【问题描述】:

我正在使用 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>

我正在使用&lt;h:messages /&gt; 来显示我的表单错误、信息和警告消息,如下所示:

<h:messages errorClass="alert alert-error" infoClass="alert alert-info" warnClass="alert alert-warning"/>

颜色和圆角都可以,但我需要添加关闭链接:

<a class="close" data-dismiss="alert" href="#">×</a>

如何使用&lt;h:messages/&gt; 做到这一点?

编辑

如果需要更好的理解,这里是警报样式的 twitter 引导链接: http://twitter.github.com/bootstrap/components.html#alerts

【问题讨论】:

    标签: html twitter-bootstrap jsf


    【解决方案1】:

    我猜你添加消息的常用方式......

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

    消息应该从服务器端添加...例如String myMessage = "here is the text / HTML code..."

    看看 BalusC 的这篇文章

    Using HTML in JSF messages

    【讨论】:

    • 好的...我将开始这样做,我在我的html 文件上这样做:&lt;h:inputText requiredMessage="O campo Pesquisa é obrigatório" id="pesquisa" styleClass="input-xxlarge search-query" required="true"/&gt; 并在我的form 顶部添加一个&lt;h:messages /&gt;,谢谢
    • 我没有尝试过这个解决方案,但它似乎是一个......欢迎您。
    【解决方案2】:

    另一种解决方案是

    <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..

    【讨论】:

      【解决方案3】:

      只需使用omnifaces o:messages。问题就解决了。

      例如&lt;o:messages escape="false"/&gt;

      【讨论】:

        猜你喜欢
        • 2012-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多