myFaces and Richfaces 4, FacesMessage not showing
jordicano Aug 18, 2011 6:51 AMHi,
I've found what it looks to be a weird behaviour with FacesMessages when using a template in RF4.
If I don't use a template the messages appear as they should, but when I use a template they don't and this other message shows on the server console:
16/08/2011 18:19:06 org.apache.myfaces.lifecycle.RenderResponseExecutor execute
WARNING: There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered.
These unhandled FacesMessages are:
- This is a FacesMessage
This is the source code:
TestFacesMessage.xhtml
<?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:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <ui:composition template="simpleTemplate.xhtml"> <ui:define name="content"> <h:form id="myForm"> <rich:messages/> <a4j:commandButton value="Show message" actionListener="#{testFacesMessage.showMessage}"/> <h:commandButton value="Hide message"> <f:ajax event="click" render="myForm" execute="@none"/> </h:commandButton> </h:form> </ui:define> </ui:composition> </html>
This is the method which adds a FacesMessage to FacesContext:
public class TestFacesMessage { public void showMessage() { FacesContext fcsContext = FacesContext.getCurrentInstance(); FacesMessage msg = new FacesMessage("This is a FacesMessage"); msg.setSeverity(FacesMessage.SEVERITY_ERROR); fcsContext.addMessage(null,msg); } }
simpleTemplate.xhtml:
<?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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title> <ui:insert name="title" >Default Title</ui:insert> </title> <style type="text/css"> body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small; } hr { margin: 0px; color: gray; } </style> </h:head> <h:body> <ui:insert name="content"> <h:outputText value="Default body" /> </ui:insert> </h:body> </html>
Any help would be appreciated.