Method from javax.faces.component.MessageFactory Detail: |
protected static Application getApplication() {
FacesContext context = FacesContext.getCurrentInstance();
if (context != null) {
return (FacesContext.getCurrentInstance().getApplication());
}
ApplicationFactory afactory = (ApplicationFactory)
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
return (afactory.getApplication());
}
|
protected static ClassLoader getCurrentLoader(Object fallbackClass) {
ClassLoader loader =
Thread.currentThread().getContextClassLoader();
if (loader == null) {
loader = fallbackClass.getClass().getClassLoader();
}
return loader;
}
|
static Object getLabel(FacesContext context,
UIComponent component) {
Object o = component.getAttributes().get("label");
if (o == null || (o instanceof String && ((String) o).length() == 0)) {
o = component.getValueExpression("label");
}
// Use the "clientId" if there was no label specified.
if (o == null) {
o = component.getClientId(context);
}
return o;
}
|
static FacesMessage getMessage(String messageId,
Object params) {
Locale locale = null;
FacesContext context = FacesContext.getCurrentInstance();
// context.getViewRoot() may not have been initialized at this point.
if (context != null && context.getViewRoot() != null) {
locale = context.getViewRoot().getLocale();
if (locale == null) {
locale = Locale.getDefault();
}
} else {
locale = Locale.getDefault();
}
return getMessage(locale, messageId, params);
}
|
static FacesMessage getMessage(String messageId,
Severity severity,
Object params) {
FacesMessage message = getMessage(messageId, params);
message.setSeverity(severity);
return message;
}
|
static FacesMessage getMessage(Locale locale,
String messageId,
Object params) {
String summary = null;
String detail = null;
ResourceBundle bundle;
String bundleName;
// see if we have a user-provided bundle
if (null != (bundleName = getApplication().getMessageBundle())) {
if (null !=
(bundle =
ResourceBundle.getBundle(bundleName, locale,
getCurrentLoader(bundleName)))) {
// see if we have a hit
try {
summary = bundle.getString(messageId);
detail = bundle.getString(messageId + "_detail");
}
catch (MissingResourceException e) {
// ignore
}
}
}
// we couldn't find a summary in the user-provided bundle
if (null == summary) {
// see if we have a summary in the app provided bundle
bundle = ResourceBundle.getBundle(FacesMessage.FACES_MESSAGES,
locale,
getCurrentLoader(bundleName));
if (null == bundle) {
throw new NullPointerException();
}
// see if we have a hit
try {
summary = bundle.getString(messageId);
detail = bundle.getString(messageId + "_detail");
} catch (MissingResourceException e) {
// ignore
}
}
// no hit found in the standard javax.faces.Messages bundle.
// check the Mojarra resources
if (summary == null) {
// see if we have a summary in the app provided bundle
bundle = ResourceBundle.getBundle(MOJARRA_RESOURCE_BASENAME,
locale,
getCurrentLoader(bundleName));
if (null == bundle) {
throw new NullPointerException();
}
// see if we have a hit
try {
summary = bundle.getString(messageId);
} catch (MissingResourceException e) {
return null;
}
}
// At this point, we have a summary and a bundle.
FacesMessage ret = new BindingFacesMessage(locale, summary, detail, params);
ret.setSeverity(FacesMessage.SEVERITY_ERROR);
return (ret);
}
|
static FacesMessage getMessage(FacesContext context,
String messageId,
Object params) {
if (context == null || messageId == null ) {
throw new NullPointerException(" context "
+ context
+ " messageId "
+ messageId);
}
Locale locale;
// viewRoot may not have been initialized at this point.
if (context.getViewRoot() != null) {
locale = context.getViewRoot().getLocale();
} else {
locale = Locale.getDefault();
}
if (null == locale) {
throw new NullPointerException(" locale is null ");
}
FacesMessage message = getMessage(locale, messageId, params);
if (message != null) {
return message;
}
locale = Locale.getDefault();
return (getMessage(locale, messageId, params));
}
|
static FacesMessage getMessage(Locale locale,
String messageId,
Severity severity,
Object params) {
FacesMessage message = getMessage(locale, messageId, params);
message.setSeverity(severity);
return message;
}
|
static FacesMessage getMessage(FacesContext context,
String messageId,
Severity severity,
Object params) {
FacesMessage message = getMessage(context, messageId, params);
message.setSeverity(severity);
return message;
}
|