Referencing values from ValidationMessages.properties
I've got a ValidationMessages.properties file that I need to reference a value from a managed bean.
This is the mb:
Code :
public class ButtonBean implements Serializable {
public void save(ActionEvent actionEvent) {
addMessage(???????HOW DO I GET THIS VALUE FROM THE ValidationMessages.properties FILE???????);
}
public void update(ActionEvent actionEvent) {
addMessage("Data updated");
}
public void delete(ActionEvent actionEvent) {
addMessage("Data deleted");
}
public void addMessage(String summary) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, null);
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
Getting the value in the JSF page is no probs but I can't figure out how to get it from inside the method. Anybody got any ideas?
Re: Referencing values from ValidationMessages.properties
Just to clarify I was trying to extract string from my resource bundle and insert it into the managed bean directly. The solution that I came up with is probably not the most elegant and any improvements would be very welcome.
Code :
public static String getResourceBundleString(String resourceBundleName, String resourceBundleKey) throws MissingResourceException {
FacesContext facesContext = FacesContext.getCurrentInstance();
ResourceBundle bundle = facesContext.getApplication().getResourceBundle(facesContext, resourceBundleName);
return bundle.getString(resourceBundleKey);
}
You can then reference the method with the name of your bundle as set in your faces-config.xml file and the name of the key for the specific string.