2 Replies Latest reply on Oct 11, 2011 9:06 PM by dance

    Fileupload triggered messages do not display

    Panayiotis Karabassis Newbie

      I am using RichFaces 4. My problem is that the message does not appear at all. If I use rich:message the message appears briefly then dissapears.

       

      This is the controller:

       

          public void uploadListener(final FileUploadEvent event) throws IOException

          {

              final UploadedFile item = event.getUploadedFile();

       

              final FacesContext context = FacesContext.getCurrentInstance();

              final Application application = context.getApplication();

              final String messageBundleName = application.getMessageBundle();

              final Locale locale = context.getViewRoot().getLocale();

              final ResourceBundle resourceBundle = ResourceBundle.getBundle(messageBundleName, locale);

       

              final String msg = resourceBundle.getString("upload.failed");

              final String detailMsgPattern = resourceBundle.getString("upload.failed_detail");

                     

              try

              {

                  CSVImporter.doImport(item.getInputStream(), registry, item.getName());

              }

              catch (ParseException e)

              {

                  final Object[] params = {item.getName(), e.getMessage()};

                  final String detailMsg = MessageFormat.format(detailMsgPattern, params);

                  final FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, detailMsg);

                 

                  context.addMessage("uploadForm:uploader", facesMsg);

              }

              catch (TokenMgrError e)

              {

                  final Object[] params = {item.getName(), e.getMessage()};

                  final String detailMsg = MessageFormat.format(detailMsgPattern, params);

                  final FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, detailMsg);

                 

                  context.addMessage("uploadForm:uploader", facesMsg);

              }

          }

       

      And this is the view:

       

          <h:form id="uploadForm" enctype="multipart/form-data">

              <h:message id="message" showDetail="true" for="uploader" errorClass="error" warnClass="warning" infoClass="info" fatalClass="fatal"/>

              <rich:fileUpload id="uploader"

                       fileUploadListener="#{itemController.uploadListener}"

                              maxFilesQuantity="1"

                              acceptedTypes="csv">

                  <a4j:ajax event="uploadcomplete" execute="@none" render="items, message" />

              </rich:fileUpload>

          </h:form>

       

      In both cases Firebug reports an empty message field being sent.

       

          <?xml version='1.0' encoding='UTF-8'?>

          <partial-response><changes><update id="uploadForm:message"><![CDATA[<span id="uploadForm:message"></span>]]></update><update id="j_idt16:items"><![CDATA[<table id="j_idt16:items">

          <thead>

          <tr>

          <th scope="col">

                                  Titles

                              </th>

          </tr>

          </thead>

          <tbody>

          <tr><td></td></tr></tbody>

          </table>

          ]]></update><update id="javax.faces.ViewState"><![CDATA[8859542538952100446:6041172679113548382]]></update></changes></partial-response>