覆盖JSF Primefaces消息标记 [英] Overriding JSF Primefaces Message Tag

查看:102
本文介绍了覆盖JSF Primefaces消息标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否可以覆盖<p:message ../>的默认实现以始终隐式拥有display="text"而不是及时输入?

Can I override the default implementation of <p:message ../> to always implicitly have display="text" instead of typing out in full in time?

<p:message for="hotelName" display="text" />

推荐答案

您可以为此扩展PrimeFaces的MessageRenderer.只需覆盖encodeEnd()方法,即可在调用super方法之前设置默认属性.

You could extend the PrimeFaces' MessageRenderer for that. Just override the encodeEnd() method wherein you set the default attribute before calling the super method.

这是一个自包含的启动示例:

Here's a self-containing kickoff example:

package com.example;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import org.primefaces.component.message.MessageRenderer;

public class CustomMessageRenderer extends MessageRenderer {

    @Override
    public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
        component.getAttributes().put("display", "text"); // You might want to check first if it isn't already set.
        super.encodeEnd(facesContext, component);
    }

}

,您需要按以下方式在faces-config.xml中进行注册(不,注释魔术无法覆盖XML本身注册的现有渲染器,因此XML是绝对必要的):

which you need to register in faces-config.xml as follows (no, annotation magic won't work in overriding the existing renderers which are by itself registered by XML, so the XML is absolutely necessary):

<render-kit>
    <renderer>
        <component-family>org.primefaces.component</component-family>
        <renderer-type>org.primefaces.component.MessageRenderer</renderer-type>
        <renderer-class>com.example.CustomMessageRenderer</renderer-class>
    </renderer>
</render-kit>

但是更简单的方法是只放入一些CSS来隐藏图标.

But easier would be to just throw in a little bit of CSS to hide the icon.

.ui-message-error-icon {
    display: none;
}

按照另一个答案的建议创建复合组件并不是一件容易的事,因为<p:message>for目标未包含在同一复合物中.

Creating a composite component as suggested by the other answer isn't exactly trivial because the for target of the <p:message> isn't contained within the same composite.

这篇关于覆盖JSF Primefaces消息标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆