2 Replies Latest reply on Jul 21, 2010 8:02 PM by shane lee

    FaceMessages question

    shane lee Newbie

      Seam 2.2.0.GA


      When im uploading file, i validate the content type. If it is not the correct type, i return a info message explaining this to the user.


      The java doc for add to Control explains:




      addToControl(String id, String messageTemplate, Object... params)
      Create a new status message, with the messageTemplate is as the message. The message will be added to the widget specified by the ID. The algorithm used determine which widget the id refers to is determined by the view layer implementation in use. A severity of INFO will be used, and you can specify parameters to be interpolated

      My code snippet for this is:



        <s:decorate id="fileUploadDecoration" template="layout/edit.xhtml">
                               <ui:define name="label">Pathname</ui:define>
                               <s:fileUpload id="file" 
                                         accept="application/pdf"
                                          data="#{newAttachment.doc}"
                                          contentType="#{newAttachment.fileContentType}"
                                          fileName="#{newAttachment.fileName}"
                                          fileSize="#{newAttachment.fileSize}"/>
                          </s:decorate>
                          
                          
                          
                          
      public void addAttachment(){       
              if(!attachment.getFileContentType().matches("application/pdf")){
                  facesMessages.addToControl("file", "Invalid file type {0}", attachment.getFileContentType());
                  return;
              } 
          }



      As you can see i have specified the id to be file, so when i see the info message i wa hoping to see it added to the widget, instead i see the message at the top based on the template im using. This does mean template supercedes or is the info message not been displayed at the correct location on my page?


      Thanks,
      Shane.






        • 1. Re: FaceMessages question
          Herberson Silva Newbie

          Try put this <rich:message for="file" /> after the <s:fileUpload/> tag.

          • 2. Re: FaceMessages question
            shane lee Newbie

            Hi Herberson,
            I tried that but it does not work.




             <s:decorate id="fileUploadDecoration" template="layout/edit.xhtml">
            <ui:define name="label">Pathname</ui:define>
            <s:fileUpload id="file" 
                 accept="application/pdf"
            data="#{newAttachment.doc}"
            contentType="#{newAttachment.fileContentType}"
            fileName="#{newAttachment.fileName}"
            fileSize="#{newAttachment.fileSize}"/>
            <rich:message for="file" />
            </s:decorate>





            I want to see the error message at my file upload widget location. Message prints at the top.


            It should work similar to decorating the input field with edit template, whereby if field is required, i see an error message appended to the right of the field. Thats what i want.