001
014
015 package com.liferay.util.bridges.jsf.common;
016
017 import com.liferay.portal.kernel.language.LanguageUtil;
018
019 import java.util.Locale;
020
021 import javax.faces.application.FacesMessage.Severity;
022 import javax.faces.application.FacesMessage;
023 import javax.faces.context.FacesContext;
024
025
035 public class FacesMessageUtil {
036
037 public static void error(FacesContext facesContext, String key) {
038 error(null, facesContext, key);
039 }
040
041 public static void error(
042 FacesContext facesContext, String key, Object argument) {
043
044 error(null, facesContext, key, argument);
045 }
046
047 public static void error(
048 FacesContext facesContext, String key, Object[] arguments) {
049
050 error(null, facesContext, key, arguments);
051 }
052
053 public static void error(
054 String clientId, FacesContext facesContext, String key) {
055
056 _addMessage(clientId, facesContext, FacesMessage.SEVERITY_ERROR, key);
057 }
058
059 public static void error(
060 String clientId, FacesContext facesContext, String key,
061 Object argument) {
062
063 _addMessage(
064 clientId, facesContext, FacesMessage.SEVERITY_ERROR, key, argument);
065 }
066
067 public static void error(
068 String clientId, FacesContext facesContext, String key,
069 Object[] arguments) {
070
071 _addMessage(
072 clientId, facesContext, FacesMessage.SEVERITY_ERROR, key,
073 arguments);
074 }
075
076 public static void info(FacesContext facesContext, String key) {
077 info(null, facesContext, key);
078 }
079
080 public static void info(
081 FacesContext facesContext, String key, Object argument) {
082
083 info(null, facesContext, key, argument);
084 }
085
086 public static void info(
087 FacesContext facesContext, String key, Object[] arguments) {
088
089 info(null, facesContext, key, arguments);
090 }
091
092 public static void info(
093 String clientId, FacesContext facesContext, String key) {
094
095 _addMessage(clientId, facesContext, FacesMessage.SEVERITY_INFO, key);
096 }
097
098 public static void info(
099 String clientId, FacesContext facesContext, String key,
100 Object argument) {
101
102 _addMessage(
103 clientId, facesContext, FacesMessage.SEVERITY_INFO, key, argument);
104 }
105
106 public static void info(
107 String clientId, FacesContext facesContext, String key,
108 Object[] arguments) {
109
110 _addMessage(
111 clientId, facesContext, FacesMessage.SEVERITY_INFO, key, arguments);
112 }
113
114 private static void _addMessage(
115 String clientId, FacesContext facesContext, Severity severity,
116 String key) {
117
118 Locale locale = JSFPortletUtil.getLocale(facesContext);
119
120 String message = LanguageUtil.get(locale, key);
121
122 FacesMessage facesMessage = new FacesMessage(severity, message, null);
123
124 facesContext.addMessage(clientId, facesMessage);
125 }
126
127 private static void _addMessage(
128 String clientId, FacesContext facesContext, Severity severity,
129 String key, Object argument) {
130
131 Locale locale = JSFPortletUtil.getLocale(facesContext);
132
133 String message = LanguageUtil.format(locale, key, argument);
134
135 FacesMessage facesMessage = new FacesMessage(severity, message, null);
136
137 facesContext.addMessage(clientId, facesMessage);
138 }
139
140 private static void _addMessage(
141 String clientId, FacesContext facesContext, Severity severity,
142 String key, Object[] arguments) {
143
144 Locale locale = JSFPortletUtil.getLocale(facesContext);
145
146 String message = LanguageUtil.format(locale, key, arguments);
147
148 FacesMessage facesMessage = new FacesMessage(severity, message, null);
149
150 facesContext.addMessage(clientId, facesMessage);
151 }
152
153 }