FacesMessages do not display when enqueued by fileUpload upl
ultrapod May 28, 2008 10:36 AMi'm having a problem with rich:fileUpload and rich:messages. simply put, the rich:messages component will not display any FacesMessages that have been enqueued by the rich:fileUpload upload listener, and this failure happens silently - i get no "FacesMessage(s) have been enqueued, but may not have been displayed." warning in my logs.
messages get displayed just fine if i enqueue them from a 'standard' control like an a4j:commandButton. in this case i set immediate="true" so that the action method of the commandButton and the upload listener method of the fileUpload components both get called during the APPLY_REQUEST_VALUES phase.
here's my jsp:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%> <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%> <f:view> <html> <body> <a4j:form id="testbed_form"> <h:outputText value = "Testing:"/> <rich:fileUpload id="test_upload" fileUploadListener="#{TestbedBean.testUploadListener}" maxFilesQuantity="1" listHeight="60" uploadControlLabel="Test File Upload" required="false"> </rich:fileUpload> <a4j:commandButton id="test_action" value="Test Action" action="#{TestbedBean.testAction}" immediate="true"> </a4j:commandButton> <rich:panel> <f:facet name="header"> <h:outputText value = "test_upload message"/> </f:facet> <rich:message for="test_upload" style="color: red"/> </rich:panel> <rich:panel> <f:facet name="header"> <h:outputText value = "test_action message"/> </f:facet> <rich:message for="test_action" style="color: red"/> </rich:panel> <rich:panel> <f:facet name="header"> <h:outputText value = "global messages"/> </f:facet> <rich:messages globalOnly="true" style="color: red"/> </rich:panel> <rich:panel> <f:facet name="header"> <h:outputText value = "non-global messages"/> </f:facet> <rich:messages globalOnly="false" style="color: red"/> </rich:panel> </a4j:form> </body> </html> </f:view>
and here's my backing bean:
import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import org.apache.log4j.Logger; import org.richfaces.event.UploadEvent; public class TestbedBean { private static Logger logger = Logger.getLogger(TestbedBean.class.getName()); public void testUploadListener(UploadEvent event) { logger.info("testUploadListener()"); int counter; for (counter = 0; counter <=10; counter++) { String errstr = "Testing message display: \'" + counter + "\'"; reportErrorToMessageHandler(errstr + " - upload global", errstr + " - upload global", null); reportErrorToMessageHandler(errstr + " - upload local", errstr + " - upload local", "testbed_form:test_upload"); } return; } public String testAction() { logger.info("testAction()"); int counter; for (counter = 0; counter <=10; counter++) { String errstr = "Testing message display: \'" + counter + "\'"; reportErrorToMessageHandler(errstr + " - action global", errstr + " - action global", null); reportErrorToMessageHandler(errstr + " - action local", errstr + " - action local", "testbed_form:test_action"); } return ""; } public static void reportErrorToMessageHandler(String summary, String detail, String componentID) { reportMessageToMessageHandler(FacesMessage.SEVERITY_ERROR, summary, detail, componentID); } public static void reportMessageToMessageHandler(FacesMessage.Severity severity, String summary, String detail, String componentID) { FacesContext context = FacesContext.getCurrentInstance(); FacesMessage message = new FacesMessage(severity, summary, detail); context.addMessage(componentID, message); } }
i strongly suspect that this is a bug, as i can see no reason why i shouldn't be able to enqueue FacesMessages from the fileUpload control upload listener.