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

    Problem with seam's file upload

    Max Meyers Newbie


      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:graphicImage value="/img/close.png" style="cursor:pointer" id="closeLink"/>
                     <rich:componentControl for="uploadPanel" attachTo="closeLink" operation="hide" event="onclick"/>
                <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)}"/>

      This is the code of my TfotoHome:

      public class TfotoHome extends EntityHome<Tfoto> {
           Log log;
           public void setTfotoTfotoId(Integer id) {
           public Integer getTfotoTfotoId() {
                return (Integer) getId();
           protected Tfoto createInstance() {
                Tfoto tfoto = new Tfoto();
                return tfoto;
           public void wire() {
           public boolean isWired() {
                return true;
           public Tfoto getDefinedInstance() {
                return isIdDefined() ? getInstance() : null;
           public String addAvatar(Tuser tuser) {
                Tfoto foto = this.getInstance();
                String persist = "";
                     log.info("foto is null");
                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.



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

          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:

          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:

          public class UploadActionBean implements UploadAction {
              @Logger private Log log;
              @In FacesMessages facesMessages;
              Tfoto tfoto;
              Tuser tuser;
              public void uploadAction() {
                  //implement your business logic here
                  log.info("UploadAction.uploadAction() action called");
              //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());

          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?


          • 2. Re: Problem with seam's file upload
            Raghunath Nandy Newbie


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


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

              • 5. Re: Problem with seam's file upload
                Paul Keogh Novice


                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.