9 Replies Latest reply on Oct 19, 2010 8:27 PM by c821124

    rich:fileUpload listener is jumping out of the conversation

    bogdanminciu.bogdan.minciu.yahoo.com

      Hello guys and girls,


      I'm using RichFaces 3.2.1-SNAPSHOT, Seam 2.0.1-GA and Facelets.


      I try to use the rich:fileUpload component to upload 5 pictures at once. This is from my editImageSet.xhtml page:


      <rich:fileUpload fileUploadListener="#{imageSetView.imageUploadListener}"
                                               maxFilesQuantity="5"
                                               id="upload"
                                               acceptedTypes="jpg, jpeg, gif, png">
                                  <a:support event="onuploadcomplete" reRender="currentImageSetA, messagesA" />
                              </rich:fileUpload>
      



      The editImageSet.xhtml page is called like this: <s:link action="#{imageSetView.editImageSet(imageSet)}" view="editImageSet.xhtml" value="edit"/>, so it starts a new CONVERSATION when entering the page.


      And this is my listener:


      @Stateful
      @AutoCreate
      @Name("imageSetView")
      @Scope(ScopeType.CONVERSATION)
      public class ImageSetViewBean implements LocalImageSetView {
      ...
      
          @In
          private EntityManager entityManager;
      
          private ImageSet currentImageSet;
      
          @Begin(join = true)
          public void editImageSet(ImageSet selectedImageSet) {
              setCurrentImageSet(imageSetDAO.findImageSetById( selectedImageSet.getId() ));
              
              setImages(currentImageSet.getImages());
              log.info("images= #0", getImages());
          }
      
          // also tried without the @Begin
          // also tried with @Begin(join = true)
          @Begin(nested = true)
          public void imageUploadListener(org.richfaces.event.UploadEvent event) throws IOException {
              if (event == null) {
                  log.warn("imageUploadListener(): null upload event");
                  return;
              }
              
              org.richfaces.model.UploadItem item = event.getUploadItem();
      
              if(item.isFile()) {
                  java.io.File tempFile = item.getFile();
                  fileName = tempFile.getAbsolutePath();
                  
      // ---
      // --- some image copying, resizing that was removed from this forum post ---
      // ---
      
                  try {
                      Image db_main = new Image();
                      db_main.setUrl(fileName);
      
                      log.info("em= #0, db_main= #1", entityManager, db_main);
                      entityManager.persist(db_main);
                      
                      currentImageSet.getImages().add(db_main);
                      entityManager.merge(currentImageSet);
                      
                  } catch(Throwable t) {
                      t.printStackTrace();
                      return;
                  }
                  
              }
              
              log.info("Image uploaded.");
          }
      ...
      }
      



      Well, the problem is when it comes to the entityManager.persist(db_main) line. It jumps out to the /home.xhtml page saying that The conversation ended, timed out or was processing another request. If I comment the lines that deal with the database (persist, merge) everything works well, all 5 files are uploaded, resized, moved.


      The interesting thing is that the first file (image) uploaded is saved on disk, and even persisted. And it is even added to the currentImageSet. So the method works well just for the first file.


      I investigated this using the Seam Debug Page, and I have seen that the conversation was still active, but somehow, the imageUploadListener() jumped out of it, even if it is annotated with @Begin(join=true).


      Could anyone please tell me why is the imageUploadListener() method jumping out of the conversation if it calls the entityManager?


      Thank you in advance for any hint,


      Bogdan.