• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I get the rendered text of a FacesMessage server side?

 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all-
I'm writing some custom validation code and want to piggy back on JSF. I'm using the resources file for my message templates but in certain cases want to handle the rendering differently. Ideally I would create a FacesMessage with my msg template and parms and then extract the completed msg text server side. Is there any way I can do this with JSF?
thanks
Max
 
Denise Smith
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean like--generate your own faces error and use a message bundle for the error message??
//method
protected void getBundleMsgSetError(String key) {
// Look up the requested message text

try {
ResourceBundle bundle = ResourceBundle.getBundle(
"some.prop.file.Msgs", getFacesContext()
.getViewRoot().getLocale());
text = bundle.getString(key);
} catch (Exception e) {
}
// Construct and add a FacesMessage containing it
getFacesContext().addMessage("",
new FacesMessage(FacesMessage.SEVERITY_ERROR, text, text));
}

//or just make a new Faces message when you need to:

getFacesContext().addMessage(
"",
new FacesMessage(FacesMessage.SEVERITY_ERROR,
getMsg(), getMsg()));
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!