• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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

 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()));
 
Police line, do not cross. Well, this tiny ad can go through:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic