Forums Register Login
custom h:message renderer
Hi there,

I would like to create a custom message renderer to renders h:message as a 'p' html element instead of as a 'span' element. It concerns the following message tag: <h:message id="firstNameErrorMsg" for="firstname" class="error-msg" />. I've written to code underneath, but that's only rendering an empty 'p' element. I suppose I have to copy all attributes and text from the original component and write it to the writer. However, I don't know where to find everything and it seems to be a lot of work for just a replacement of a tag.

Is there a better way to get an h:message tag rendered as a 'p' element?


Thanks and kind regards,

Hi John,

Welcome to CodeRanch!

First of all, please UseCodeTags (⇐Click) when posting code here.

I think you what would work for you is styling the message with a block layout, like:

Even better, you could add that style to a CSS class and add a styleClass (or errorClass) attribute to h:message. It's better to use the supported attributes of h:message, rather than class.

Perfect! Thank you for your answer, Greg.



I don't recommend overriding renderers in JSF for standard tags. If you absolutely must change how a tag renders and you can't do it by less intrusive methods (such as CSS), subclass the tag. That way you A) won't interfere with other uses of the tag and B) won't confuse other developers when the tag doesn't "work right". Because seeing a different tag is a strong cue that it has different behavior.
You're welcome, John. I'm glad that worked.

This thread has been viewed 1884 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 15, 2018 17:15:09.