Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting messages to <h:message>  RSS feed

 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am wondering, if it is possible to set error messages to a <h:message> field from a custom function, that is not a validator function. So if in my register function I do some checks and realize that there is a problem with the data in the form, then set an error message to the form field with the error.
So I thought that if I have different inputs with their associated <h:message> the I can bind the message field to the backing bean, and then use some method on the HtmlMessage class to set a custom message. But I've been doing some tests and no message shows up.

Can anyone tell me if this is possible and how to do it? I want to do it without creating validators, I know I could do it with validators, but I'm just wondering if it is possible to do it in a different way.

Thanks!
 
Tim Holloway
Bartender
Posts: 18713
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. It's documented in the JSF API. I usually define a "JSFUtils" class that I put stuff like this in so I don't have to splatter my backing beans with JSF-specific code. Instead, they invoke JSFUtil methods such as the ones that add messages to the JSF FcesContext message collection.
 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're absolutely right. I just wasn't looking in the right place when I first tried it. I was tying to put some message directly to the HtmlMessage object. It has to be done through getFacesContext().addMessage(HtmlMessage.id, FacesMessage), where the first attribute is the Htmlmessage id and the second one a facesMessage.
I just post this in case someone is looking for this too.

Thanks a lot Tim!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!