6 Replies Latest reply on Nov 6, 2011 1:52 PM by lfryc

    RichFaces 4 - fileUpload; CDI- Conversation scope

    kem

      Hi,

       

      fileUpload only works with SessionScope!

       

      in a conversation scope I got the following:

       

      1. During the upload file, a conversation start.
      2. the file is uploaded
      3. when I click on submit, the submit() method is called
      4. a new conversation starts
      5. the uploaded file is null.

       

      In a SessionScope, everything works fine.

       

      Does the fileUpload only works in a SessionScope?

       

      Thanks

       

       

      @Named

      @ConversationScoped

      public class UploadBean implements Serializable{

       

         private Logger log = LoggerFactory.getLogger(AnnotateBean.class);

       

         private UploadedFile uploadedFile;

        

         @Inject

         Conversation conversation;

       

         public UploadBean() {

         }

       

       

         @PostConstruct

         private void init() {

            if (conversation.isTransient()) {

               conversation.begin();

               log.debug("conversation started cid=" + conversation.getId());

            }

         }

       

       

         public void listner(FileUploadEvent event) throws IOException {

            this.uploadedFile = event.getUploadedFile();

         }

       

       

         public void submit() {

            log.debug("submit called for " + uploadedFile.getName());

         }

      }

        • 1. Re: RichFaces 4 - fileUpload; CDI- Conversation scope
          lfryc

          Hello Khalil,

           

          I think it can be caused by UploadedFile not being Serializable,

          it can help to wrap the data you have received in listener and store them as Serializable (simply storing byte[] should help).

           

          Please try that and let us know.

           

          ~ Lukas

          • 2. Re: RichFaces 4 - fileUpload; CDI- Conversation scope
            lfryc

            For example in RichFaces Showcase:

             

            https://github.com/richfaces/showcase/blob/develop/src/main/java/org/richfaces/demo/fileupload/FileUploadBean.java

             

            UploadedImage is Serializable wrapper for UploadedFile data.

            • 3. Re: RichFaces 4 - fileUpload; CDI- Conversation scope
              kem

              Hi Lukas,

               

              first of all, it works fine with @ManagedBean and @SessionScoped.

               

              The issue is related to CDI and @ConversationScoped.

               

              tried with the example from the book (rf4 2nd). Just added @PostConstruct and PreDestroy methods.

               

              Here is the source of the problem: each time the fileUpload.jsf is refreshed, a new conversation starts. It's apparently related to conversation propagation issue. Still I don't know how to fix it.

               

              here is the log:

              INFO: conversation started cid=1

              INFO: conversation started cid=2

              INFO: file uploaded

              INFO: conversation started cid=3

               

               

              //@ManagedBean

              //@SessionScoped

              @Named

              @ConversationScoped

              public class FileUploadBean implements Serializable {

               

              private ArrayList<UploadedFile> files = new ArrayList<UploadedFile>();

                 @Inject

                 Conversation conversation;

                 Logger log = Logger.getAnonymousLogger();

               

               

                 public FileUploadBean() {

                 }

               

               

                 @PostConstruct

                 public void init() {

                    if (conversation.isTransient()) {

                       conversation.begin();

                       log.info("conversation started");

                    }

                 }

               

               

                 @PreDestroy

                 public void destroy() {

                    if (!conversation.isTransient()) {

                       conversation.end();

                       log.info("conversation ended");

                    }

                 }

              ....

              }

               

              Regards,

               

              Khalil

              • 4. Re: RichFaces 4 - fileUpload; CDI- Conversation scope
                lfryc

                Khalil, it would be great if you could provide sample for reproduction.

                • 5. Re: RichFaces 4 - fileUpload; CDI- Conversation scope
                  kem

                  Hi Lukas,

                   

                  here is FileUploadBean and view file. The example came from RF4 book

                   

                  you can do the test as

                   

                  @ManagedBean

                  @SessionScoped

                   

                  OR

                   

                  @Named

                  @ConversationScoped

                   

                   

                  to add something else ;-), the maxFilesQuantity in the view is not available!!

                   

                  Regards,

                   

                  Khalil

                  • 6. Re: RichFaces 4 - fileUpload; CDI- Conversation scope
                    lfryc

                    Hi Khalil,

                     

                    thanks for your sample!

                     

                    Regrettably I didn't have time to look into this issue last few days,

                    could you please open issue in RichFaces issue tracker note details so we can schedule it appropriately?

                     

                     

                    Basically if FileUpload works with @SessionScoped and @ViewScoped, we need to make it work with @ConversationScope.

                     

                     

                    Thanks,

                     

                    ~ Lukas