Java examples for JSF:FacesContext
create Error Message for JSF FacesContext
import java.util.ResourceBundle; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; public class Main{ public static void main(String[] argv) throws Exception{ String key = "java2s.com"; System.out.println(createErrorMessage(key)); }//from www. java 2 s . c om public static FacesMessage createErrorMessage(String key) { return new FacesMessage(FacesMessage.SEVERITY_ERROR, "", getMessages(key)); } public static String getMessages(String key) { FacesContext context = FacesContext.getCurrentInstance(); ResourceBundle bundle = ResourceBundle.getBundle( "com.formation.bundle.messagesErr", context .getApplication().getDefaultLocale()); String message = null; try { message = bundle.getString(key); } catch (Exception e) { return "unkown message " + key; } return message; } }