-
1. Re: rich:fileUpload ends conversation in Seam
damnre Apr 3, 2008 9:44 AM (in response to majeric)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
majeric Apr 3, 2008 10:35 AM (in response to majeric)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" /> </rich:fileUpload>
pages.xml<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}" /> <navigation> <rule if="#{empty(gallery)}"> <redirect view-id="/galleries.xhtml"/> </rule> </navigation> </page>
web.xml<?xml version="1.0" ?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <!-- Ajax4jsf --> <context-param> <param-name>org.richfaces.SKIN</param-name> <param-value>blueSky</param-value> </context-param> <!-- Seam --> <listener> <listener-class>org.jboss.seam.servlet.SeamListener</listener-class> </listener> <filter> <filter-name>Seam Filter</filter-name> <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class> </filter> <filter-mapping> <filter-name>Seam Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> <init-param> <param-name>logLevel</param-name> <param-value>ERROR</param-value> </init-param> </filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>Seam Resource Servlet</servlet-name> <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Seam Resource Servlet</servlet-name> <url-pattern>/seam/resource/*</url-pattern> </servlet-mapping> <!-- Facelets development mode (disable in production) --> <context-param> <param-name>facelets.DEVELOPMENT</param-name> <param-value>true</param-value> </context-param> <!-- JSF --> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.seam</url-pattern> </servlet-mapping> <context-param> <param-name>facelets.SKIP_COMMENTS</param-name> <param-value>true</param-value> </context-param> <security-constraint> <display-name>Restrict raw XHTML Documents</display-name> <web-resource-collection> <web-resource-name>XHTML</web-resource-name> <url-pattern>*.xhtml</url-pattern> </web-resource-collection> <auth-constraint/> </security-constraint> </web-app>
component.xml<core:manager concurrent-request-timeout="1500" conversation-timeout="300000" conversation-id-parameter="cid"/> <!-- 2097152 = 2MB --> <web:multipart-filter url-pattern="*.seam" max-request-size="2097152" create-temp-files="true"/> <security:identity authenticate-method="#{authenticator.authenticate}" security-rules="#{securityRules}" /> <persistence:managed-persistence-context auto-create="true" name="entityManager" 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"); return; } 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); picture.setThumb("/"+path+thumbName); picture.setMedium("/"+path+mediumName); picture.setLarge("/"+path+largeName); picture.setGallery(editGallery); this.saveTagsToPicture(picture); editGallery.getPictures().add(picture); log.info("uploadPicture finished...."); } catch (IOException e) { log.error(e.getMessage()); } catch (Exception e) { log.error(e.getMessage()); 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()) .getRealPath("/")+path; log.info("data (saveImageToDisk): "+data); image.scaleToWidth(width); 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); this.uploadPicture(); log.info("after uploadPicture"); getGalleryPictures(); facesMessages.addFromResourceBundle("image_uploaded"); }
Thanks, -
3. Re: rich:fileUpload ends conversation in Seam
majeric Apr 4, 2008 5:28 AM (in response to majeric)Any suggestion?
Uros -
4. Re: rich:fileUpload ends conversation in Seam
sergeysmirnov Apr 4, 2008 1:09 PM (in response to majeric)if you use rich:fileUpload, the seam multipart filter must be turned off.
-
5. Re: rich:fileUpload ends conversation in Seam
majeric Apr 7, 2008 4:55 AM (in response to majeric)I have added:
<filter-name>Seam Multipart Filter</filter-name> <filter-class>org.jboss.seam.web.MultipartFilter</filter-class> </filter> <filter-mapping> <filter-name>Seam Multipart Filter</filter-name> <url-pattern>*.seam</url-pattern> </filter-mapping>
in my web.xml file, but still doesn't work. It still ends my conversation!
Uros -
6. Re: rich:fileUpload ends conversation in Seam
majeric Apr 7, 2008 5:06 AM (in response to majeric)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-class>org.jboss.seam.web.MultipartFilter</filter-class> </filter> <filter-mapping> <filter-name>Seam Multipart Filter</filter-name> <url-pattern>*.seam</url-pattern> </filter-mapping>
and changed:<web:multipart-filter url-pattern="*.seam" max-request-size="2097152" create-temp-files="true" />
to:<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?
Uros -
7. Re: rich:fileUpload ends conversation in Seam
andrei_exadel Apr 7, 2008 6:18 AM (in response to majeric)Hi,
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?
Thanks. -
8. Re: rich:fileUpload ends conversation in Seam
majeric Apr 8, 2008 12:12 PM (in response to majeric)Hi,
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.
Uros -
9. Re: rich:fileUpload ends conversation in Seam
andrei_exadel Apr 9, 2008 8:02 AM (in response to majeric)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
nathandennis Apr 9, 2008 1:40 PM (in response to majeric)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_exadel Apr 10, 2008 6:34 AM (in response to majeric)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
bogdanminciu Apr 25, 2008 12:06 PM (in response to majeric)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"/>
to<core:manager concurrent-request-timeout="5000" conversation-timeout="180000" conversation-id-parameter="cid"/>
Thanks to Zahid: http://www.seamframework.org/Community/RichfileUploadListenerIsJumpingOutOfTheConversation