5 Replies Latest reply on Jan 4, 2009 12:43 AM by paulmkeogh

    Problem with seam's file upload

      Hello!


      I have a page, where I want to give the user the possiblity to upload an avatar. I make this in a richfaces ModalPanel. I include a seam fileUpload component and two buttons (cancel and save).


      My problem is, if I choose an image and click on the save button my action always gets as data and contentType null.


      Here is my code:


      xhtml-file (ModalPanel):



      <rich:modalPanel id="uploadPanel" height="100" width="320">
           <f:facet name="header">Fotoupload</f:facet>
           <f:facet name="controls">
                    <h:panelGroup>
                        <h:graphicImage value="/img/close.png" style="cursor:pointer" id="closeLink"/>
                     <rich:componentControl for="uploadPanel" attachTo="closeLink" operation="hide" event="onclick"/>
                    </h:panelGroup>
           </f:facet>
           <h:form>
                <s:fileUpload accept="image/png, image/gif, impage/jpeg" data="#{tfotoHome.instance.timage}" contentType="#{tfotoHome.instance.tcontenttype}" />
                <h:panelGrid columns="2">
                     <s:button value="Abbrechen"/>
                     <h:commandButton type="submit" value="Speichern" action="#{tfotoHome.addAvatar(tuser)}"/>
                </h:panelGrid>
           </h:form>
      </rich:modalPanel>



      This is the code of my TfotoHome:



      @Name("tfotoHome")
      public class TfotoHome extends EntityHome<Tfoto> {
      
           @Logger
           Log log;
           
           public void setTfotoTfotoId(Integer id) {
                setId(id);
           }
      
           public Integer getTfotoTfotoId() {
                return (Integer) getId();
           }
      
           @Override
           protected Tfoto createInstance() {
                Tfoto tfoto = new Tfoto();
                return tfoto;
           }
      
           public void wire() {
                getInstance();
           }
      
           public boolean isWired() {
                return true;
           }
      
           public Tfoto getDefinedInstance() {
                return isIdDefined() ? getInstance() : null;
           }
           
           public String addAvatar(Tuser tuser) {
                Tfoto foto = this.getInstance();
                String persist = "";
                
                if(foto==null)
                     log.info("foto is null");
                
                log.info(foto.getTcontentType());
                
                foto.setTdescription("avatar");
                foto.setTuser(tuser.getTuserId());
                this.setInstance(foto);
                log.info(persist = this.persist());
                return persist;
           }
      }



      As you can see I am calling the addAvatar method as action in my ModalPanel. When I am in my addAvatar method, my FotoInstance is not null, but it's content is (tcontentType and timage).


      I don't know why these values are null. Maybe because they are not set by the seam uploadFile component? Maybe there is some problem with the submit (so that the values are not set)?


      I tried many different things, but nothing worked (setting @In values, setting scopetype to session, ...).


      It would be great if someone of you knows what my mistake is! If you need more code, please let me know.


      Thanks!


      regards,
      max.


        • 1. Re: Problem with seam's file upload

          Now I am wondering: I changed the Tfoto to session scope and looked at the content of it. All data is in there. But why I get in my action null? I don't understand this.


          Here is a screenshot of the trace:
          trace



          And here is one of the content of Tfoto:
          tfoto session


          I wrote a new action, but it does nothing else like the old one of my first post:



          @Stateless
          @Name("UploadAction")
          public class UploadActionBean implements UploadAction {
               
              @Logger private Log log;
               
              @In FacesMessages facesMessages;
              
              @In(required=false)
              Tfoto tfoto;
              
              @In(required=false)
              Tuser tuser;
              
              public void uploadAction() {
                  //implement your business logic here
                  log.info("UploadAction.uploadAction() action called");
                  facesMessages.add("uploadAction");
              }
              
              //add additional action methods
              
              public void uploadAvatar() {
                   log.info("UploadAction.uploadAvatar() action called");
                   TfotoHome tfotoHome = new TfotoHome();
                   
                   log.info("tuserId: "+tuser.getTuserId());
                   log.info("content-type: "+ tfoto.getTcontentType());
                   log.info("image: "+tfoto.getTimage());
                   tfoto.setTuser(tuser.getTuserId());
                   tfoto.setTdescription("avatar");
                   tfotoHome.setInstance(tfoto);
                   tfotoHome.persist();
              }
              
          }




          In this I action I get null from my tfoto variable, but on the debug page I get a content.
          Does anybody know why I am getting null in my action?


          Thanks,
          max.

          • 2. Re: Problem with seam's file upload
            visumagic

            Hi


            I'm also facing same problem , are you able to fix this.
            I'm always getting null in the image content


            thanks
            raghu

            • 3. Re: Problem with seam's file upload
              visumagic
              hi
              i got it ..
              u need to keep enctype="multipart/form-data", in the h:form

              thans
              raghu
              • 4. Re: Problem with seam's file upload
                karan

                hope this helps you
                My Link


                Karan

                • 5. Re: Problem with seam's file upload
                  paulmkeogh

                  Hi,


                  Did you ever find a solution for this problem ?


                  I have the same problem - works fine as a SeamTest integration test inside JBoss embedded container but fails when executed from a browser against JBoss 4.2.3.