This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

custom h:message renderer  RSS feed

 
John Josey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Code:


Thanks and kind regards,

John
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
John Josey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect! Thank you for your answer, Greg.

Regards,

John

 
Tim Holloway
Bartender
Posts: 18713
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome, John. I'm glad that worked.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!