0

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" />
maple_shaft
  • 10,435
  • 6
  • 46
  • 74
Oh Chin Boon
  • 23,028
  • 51
  • 143
  • 215
  • Just an idea, instead of overriding which might(and maybe not) cause you troubles if the original – Daniel Feb 12 '12 at 09:55

2 Answers2

4

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);
    }

}

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>

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

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

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

I would simply create a Facelet Composition Component for that.

user793953
  • 91
  • 9