12 Replies Latest reply on Apr 25, 2008 12:06 PM by Bogdan Minciu

    rich:fileUpload ends conversation in Seam

    Uros Majeric Newbie

      Does aynone have a same problem?

      I have a page wich conversation begins in pages.xml (<begin-conversation join="true">) and when I select multiple files to upload and press the Upload button then fileUpload uploads 1st file ad then throws Conversation timeout.

      I have Seam 2.0 and richfaces 3.2.0

      Thanks, Uros

        • 1. Re: rich:fileUpload ends conversation in Seam
          I B Newbie

          could you post your configs and code sample please...
          How did you configured the web.xml and component.xml

          • 2. Re: rich:fileUpload ends conversation in Seam
            Uros Majeric Newbie

            This is my xhtml code:

             <rich:fileUpload fileUploadListener="#{galleryAction.uploadListener}"
             maxFilesQuantity="10" reRender="table" id="upload" style="width:100%;"
             immediateUpload="false" acceptedTypes="jpg, gif"
             addControlLabel="#{messages.add}" cancelEntryControlLabel="#{messages.remove}"
             clearAllControlLabel="#{messages.clear}" clearControlLabel="#{messages.clear}"
             stopControlLabel="#{messages.stop}" stopEntryControlLabel="#{messages.stop}"
             uploadControlLabel="#{messages.upload}" >
             <a4j:support event="onuploadcomplete" reRender="galleryForm" />

             <page view-id="/gallery.xhtml" login-required="true" no-conversation-view-id="/galleries.xhtml">
             <!-- <action if="#{empty(gallery)}" execute="#{galleryAction.getGallery}" /> -->
             <begin-conversation join="true" />
             <param name="gid" value="#{galleryAction.galleryId}" />
             <rule if="#{empty(gallery)}">
             <redirect view-id="/galleries.xhtml"/>

            <?xml version="1.0" ?>
            <web-app xmlns="http://java.sun.com/xml/ns/javaee"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
             <!-- Ajax4jsf -->
             <!-- Seam -->
             <filter-name>Seam Filter</filter-name>
             <filter-name>Seam Filter</filter-name>
             <servlet-name>Seam Resource Servlet</servlet-name>
             <servlet-name>Seam Resource Servlet</servlet-name>
             <!-- Facelets development mode (disable in production) -->
             <!-- JSF -->
             <servlet-name>Faces Servlet</servlet-name>
             <servlet-name>Faces Servlet</servlet-name>
             <display-name>Restrict raw XHTML Documents</display-name>

             <core:manager concurrent-request-timeout="1500"
             <!-- 2097152 = 2MB -->
             <web:multipart-filter url-pattern="*.seam" max-request-size="2097152" create-temp-files="true"/>
             security-rules="#{securityRules}" />
             <persistence:managed-persistence-context auto-create="true"
             persistence-unit-jndi-name="java:/dajvaseEntityManagerFactory" />

            and java code (if needed)
             public void uploadPicture() {
             try {
             log.info("gallery: "+editGallery+", this.fileName: "+this.fileName);
             String path = "Galleries/"+currentUser.getNickName()+"/"+editGallery.getTitle()+"/";
             String thumbName = new SimpleDateFormat("yyMMddHHmmss").format(new Date())+"_thumb";
             String mediumName = new SimpleDateFormat("yyMMddHHmmss").format(new Date())+"_medium";
             String largeName = new SimpleDateFormat("yyMMddHHmmss").format(new Date())+"_large";
             Image image = new Image().setInput(data);
             String contentType = image.getContentType().getMimeType();
             log.info("contentType: "+contentType);
             if (contentType.equals("image/gif")){
             thumbName += ".gif";
             mediumName += ".gif";
             largeName += ".gif";
             } else if (contentType.equals("image/jpeg")) {
             thumbName += ".jpg";
             mediumName += ".jpg";
             largeName += ".jpg";
             } else {
             facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_ERROR, "image_wrong_type");
             log.info("contentType: "+contentType);
            // saveImageToDisk(image, path, largeName, 1280);
             saveImageToDisk(image, path, thumbName, 150);
             saveImageToDisk(image, path, mediumName, 640);
             editGallery = entityManager.merge(editGallery);
             Picture picture = new Picture(this.fileName);
             log.info("uploadPicture finished....");
             } catch (IOException e) {
             } catch (Exception e) {
             facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_ERROR, "image_uploading_error");
             private boolean saveImageToDisk(Image image, String path, String fileName, int width) throws IOException {
             path = ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext())
             log.info("data (saveImageToDisk): "+data);
             ByteBuffer bbuf = ByteBuffer.wrap(image.getImage());
             log.info("Path: "+path+fileName);
             if (!(new File(path)).exists()){
             if (!(new File(path)).mkdirs()) {
             log.info("Directories: " + path + " created");
             return false;
             FileUtils.writeByteArrayToFile(new File(path+fileName), image.getImage());
             return true;
             public void uploadListener(UploadEvent event) throws IOException {
             UploadItem item = event.getUploadItem();
             if (item.isFile()) {
             fileName = FilenameUtils.getName(item.getFileName());
             this.data = FileUtils.readFileToByteArray( item.getFile() );
             log.info("data: "+data);
             log.info("after uploadPicture");


            • 4. Re: rich:fileUpload ends conversation in Seam
              Sergey Smirnov Master

              if you use rich:fileUpload, the seam multipart filter must be turned off.

              • 5. Re: rich:fileUpload ends conversation in Seam
                Uros Majeric Newbie

                I have added:

                 <filter-name>Seam Multipart Filter</filter-name>
                 <filter-name>Seam Multipart Filter</filter-name>

                in my web.xml file, but still doesn't work. It still ends my conversation!


                • 6. Re: rich:fileUpload ends conversation in Seam
                  Uros Majeric Newbie

                  Sorry my bed.
                  I have overlooked that multipart filter has to be turned of. So I removed:

                   <filter-name>Seam Multipart Filter</filter-name>
                   <filter-name>Seam Multipart Filter</filter-name>

                  and changed:
                   <web:multipart-filter url-pattern="*.seam" max-request-size="2097152" create-temp-files="true" />

                   <web:multipart-filter url-pattern="*.seam" max-request-size="2097152" create-temp-files="true" disabled="true" />

                  but still doesn't work.
                  Do I have to do something else?


                  • 7. Re: rich:fileUpload ends conversation in Seam
                    Andrei Markavtsov Apprentice


                    I cannot understand the workflow of your application from this part of code.

                    Can you please add issue in JIRA and attach your WAR file there?


                    • 8. Re: rich:fileUpload ends conversation in Seam
                      Uros Majeric Newbie


                      Unfortunately I can't attach my WAR file because it's big project which was made in in our company, and they wouldn't be happy if I would make it public :)

                      workflow is pretty simple. User click on a <h:commandButton /> wich opens the gallery.xhtml page. Conversation is began with this page and gallery is outjected to CONVERSATION context. but when I press the upload button application uploads me a few of files (sometimes one, othertime 3 or 4) and throws NoConversation.


                      • 9. Re: rich:fileUpload ends conversation in Seam
                        Andrei Markavtsov Apprentice

                        Anyway I cannot reproduce your problem. I created two pages. One of these contains File Upload component. This page should start conversation.

                        Another page contains commandButton which moves user to the page with file upload component.

                        I could not find any problem in this test.

                        It will be greate if you can create the simplest example where problem is reprodusible and attach it to JIRA.

                        Thanks a lot.

                        • 10. Re: rich:fileUpload ends conversation in Seam
                          nathan dennis Expert

                          I would seem that i am also experiencing this problem. It looks like the problem happens with multiple files are selected. in my case.. the first two files will land in the same object and the third in a new object. all uploads are persisted successfully,, just as if they are unrelated.. but the array containing the previews is broken by this behavior.

                          looking at the conversations independently reveals all data.

                          is it possible that the component sees one conversation is busy,, then automatically creates a second thread as a new conversation?

                          • 11. Re: rich:fileUpload ends conversation in Seam
                            Andrei Markavtsov Apprentice

                            File upload component has no any influence on conversations processing which controled by Seam framework.

                            Resolution should be find in researching with Seam, but not with file upload component.

                            • 12. Re: rich:fileUpload ends conversation in Seam
                              Bogdan Minciu Newbie

                              I solved this problem by modifying the concurrent-request-timeout value from:

                              <core:manager concurrent-request-timeout="500" conversation-timeout="120000" conversation-id-parameter="cid"/>


                              <core:manager concurrent-request-timeout="5000" conversation-timeout="180000" conversation-id-parameter="cid"/>

                              Thanks to Zahid: http://www.seamframework.org/Community/RichfileUploadListenerIsJumpingOutOfTheConversation