7

I'm using JSF messages to show the error/warning/info messages into my web application. Also I use <p:messages> to render them in the browser with different styles.

Nevertheless, I need to create a new style for some of my messages, keeping the rest of them as they are right now. In other words, I need to create an ok severity for my JSF messages, which will display the info in a green box with a tick.

Although I've been looking at library classes, it seems not to be an straight forwarded way to achieve that. Severities are stored into FacesMessages$Severity class as an enumeration and have a private constructor. Do I have to override the source code directly?

Aritz
  • 30,971
  • 16
  • 136
  • 217
  • The info severity is not for the "ok" purpose? When you do some action, if it does output info, normally this is when everything was fine no? – Alexandre Lavoie Mar 14 '13 at 12:58
  • I want to add a message when user introduces an email address. 'Ok' will be for valid address and 'error' for invalid. I wanted to differ between that message type and informative one. – Aritz Mar 14 '13 at 13:51
  • I wonder if this is still the case in JSF 2.2 – thatsIch Jan 12 '16 at 21:12

1 Answers1

3

That's not possible without hacking the JSF API/impl, no.

Just reuse the INFO severity, or abuse the one apparently unused by you: FATAL. Or, if the functional requirement is purely presentational, throw in some JS/jQuery/CSS to achieve it.

A drastic alternative would be reinventing the JSF message system with custom message wrappers and custom message components.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks for the rapid answer Balus. Is it done like that by JSF for any specific reason or could be a future improvement for them to add more flexible messaging classes? – Aritz Mar 14 '13 at 14:40
  • I agree that the design of faces messages is subject for improvements. It's also somewhat a heritage from old JSF 1.x ages. But, on the other hand, it's not possible to randomly specify custom attributes like `okStyle` or `okClass` on existing JSF message components without manipulating/extending the component and renderer. – BalusC Mar 14 '13 at 14:49
  • Any chance we see that feature in the feature? Adding custom severity levels? Do you think it would help to open a feature request? – raupach Jun 29 '13 at 12:32