[
https://issues.jboss.org/browse/RF-12063?page=com.atlassian.jira.plugin.s...
]
Brendan Healey commented on RF-12063:
-------------------------------------
Clicking into and out of the input should cause the value change listener to fire,
however no message appears on the screen. Simply adding a commandButton, and copying
the message generation code from the value change listener into an action= method
and clicking the button will cause a notifyMessage to appear on screen.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:sqcc="http://java.sun.com/jsf/composite/sqcc">
<rich:notifyMessages stayTime="3500"/>
<h:inputText valueChangeListener="#{bean.testVcl}">
<f:ajax event="blur"/>
</h:inputText>
<a4j:commandButton value="push" action="#{bean.testAction}"/>
</html>
Bean.java
---------
@Named
@ViewScoped
public class Bean implements Serializable {
public void testVcl(ValueChangeEvent event) {
//Log.log("testVcl");
FacesMessage message = getFacesMessage("helloText");
message.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage(null, message);
}
public String testAction() {
//Log.log("testVcl");
FacesMessage message = getFacesMessage("helloText");
message.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage(null, message);
}
public static FacesMessage getFacesMessage(String msgKey) {
FacesMessage message = Messages.getMessage("messages",
msgKey, null);
return message;
}
Messages.java
-------------
package uk.co.myproj.test;
/**
*
* @author Brendan Healey
* copied from Core JSF Geary/Horstmann p249
*/
import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
public class Messages {
public static FacesMessage getMessage(String bundleName, String resourceId,
Object[] params) {
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();
String appBundle = app.getMessageBundle();
Locale locale = getLocale(context);
ClassLoader loader = getClassLoader();
String summary = getString(appBundle, bundleName, resourceId,
locale, loader, params);
if (summary == null) {
summary = "???" + resourceId + "???";
}
String detail = getString(appBundle, bundleName, resourceId +
"_detail",
locale, loader, params);
return new FacesMessage(summary, detail);
}
public static String getString(String bundle, String resourceId,
Object[] params) {
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();
String appBundle = app.getMessageBundle();
Locale locale = getLocale(context);
ClassLoader loader = getClassLoader();
return getString(appBundle, bundle, resourceId, locale, loader, params);
}
public static String getString(String bundle1, String bundle2,
String resourceId, Locale locale, ClassLoader loader,
Object[] params) {
String resource = null;
ResourceBundle bundle;
if (bundle1 != null) {
bundle = ResourceBundle.getBundle(bundle1, locale, loader);
if (bundle != null) {
try {
resource = bundle.getString(resourceId);
} catch (MissingResourceException ex) {
}
}
}
if (resource == null) {
bundle = ResourceBundle.getBundle(bundle2, locale, loader);
if (bundle != null) {
try {
resource = bundle.getString(resourceId);
} catch (MissingResourceException ex) {
}
}
}
if (resource == null) {
return null; // no match
}
if (params == null) {
return resource;
}
MessageFormat formatter = new MessageFormat(resource, locale);
return formatter.format(params);
}
public static Locale getLocale(FacesContext context) {
Locale locale = null;
UIViewRoot viewRoot = context.getViewRoot();
if (viewRoot != null) {
locale = viewRoot.getLocale();
}
if (locale == null) {
locale = Locale.getDefault();
}
return locale;
}
public static ClassLoader getClassLoader() {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
loader = ClassLoader.getSystemClassLoader();
}
return loader;
}
}
rich:notifyMessages not displaying error from valueChangeListener
-----------------------------------------------------------------
Key: RF-12063
URL:
https://issues.jboss.org/browse/RF-12063
Project: RichFaces
Issue Type: Feature Request
Security Level: Public(Everyone can see)
Components: component-output
Affects Versions: 4.2.0.Final
Environment: Mojarra 2.1.7, RF 4.2.0.Final, Windows 7, Glassfish 3.1.2, Chrome
browser.
Reporter: Brendan Healey
Labels: waiting_on_user
I have a global notifyMessages in a template <rich:notifyMessages
stayTime="3500"/>.
I log a global error in the usual way from a value change listener (process validations
phase):
FacesMessage message = getFacesMessage(errKey);
message.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage(null, message);
but the error never appears. If I have an h:messages on the page which is ajax
rendered the message appears ok.
Regards,
Brendan.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira