Note that there are some explanatory texts on larger screens.

plurals
  1. POIntegrating Flash File Upload with JSF
    primarykey
    data
    text
    <p>I have seen that we can upload multiple files by flash file upload. Like <a href="http://code.google.com/p/swfupload/" rel="nofollow noreferrer">SWFUpload</a> or <a href="http://yuilibrary.com/yui/docs/uploader/" rel="nofollow noreferrer">YUI Uploader</a>. Is it possible to integrate these upload component with JSF?</p> <p>What I want is to choose multiple file at once. Primefaces file uploader has this feature, but that don't work in IE7 as IE7 don't have any support for HTML5. </p> <p>I need to create a Form with various fields, like dropdown menu, text input etc and also need to add a file uploader for choosing multiple file. When the JSF submit button will be clicked the Form will be validated and it will proceed after.</p> <p>I have created a page for uploading multiple file, but that page use multiple input file component for multiple file.</p> <p>Any reference would be very helpful for me. I have found another <a href="https://stackoverflow.com/questions/2922344/need-an-example-of-using-swfupload-with-java">SO thread</a> and the solution posted there use JSP. I cannot understand how can I use this to fulfill my requirement.</p> <h2>Update</h2> <p>I have created the following managed bean:</p> <pre><code>import com.mhis.massupload.ucm.Service; import java.util.List; import java.util.UUID; import java.util.logging.Logger; import javax.faces.context.FacesContext; import org.apache.commons.fileupload.FileItem; public class UploadBean { private Logger log = Logger.getLogger(getClass().getName()); private Service service; private String key; public UploadBean() { super(); log.info("JYM"); init(); } private void init() { key = UUID.randomUUID().toString(); } public String upload() { System.out.println("Action Invoked."); List&lt;FileItem&gt; fileFields = (List&lt;FileItem&gt;)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(key); System.out.println(fileFields); return ""; } public void setKey(String key) { this.key = key; } public String getKey() { return key; } } </code></pre> <p>And the Servlet is:</p> <pre><code>import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; public class UploadServlet extends HttpServlet { @SuppressWarnings("compatibility:-3560436533054762606") private static final long serialVersionUID = 4122845079663279030L; public void init(ServletConfig config) throws ServletException { super.init(config); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("UploadServlet invoked."); List&lt;FileItem&gt; fileFields = new ArrayList&lt;FileItem&gt;(); try { List&lt;FileItem&gt; items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) { fileFields.add(item); System.out.println(item.getName()); } } } catch (Exception e) { throw new ServletException(e); } String key = request.getParameter("key"); request.getSession().setAttribute(key, fileFields); } } </code></pre> <p>The jspx page:</p> <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt; &lt;jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"&gt; &lt;jsp:output omit-xml-declaration="true" doctype-root-element="HTML" doctype-system="http://www.w3.org/TR/html4/loose.dtd" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/&gt; &lt;jsp:directive.page contentType="text/html;utf-8"/&gt; &lt;f:view&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt; &lt;script src="js/jquery-1.8.3.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="uploadify/jquery.uploadify.js" type="text/javascript"&gt;&lt;/script&gt; &lt;link rel="stylesheet" media="screen" href="uploadify/uploadify.css" type="text/css"/&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('#uploadify').uploadify({ 'swf': 'uploadify/uploadify.swf', 'uploader': '${pageContext.request.contextPath}/uploadServlet;jsessionid=${pageContext.session.id}?key=&lt;h:outputText value="#{uploadBean.key}" /&gt;' }); }); var upload = function() { $('#uploadify').uploadify('upload','*'); } &lt;/script&gt; &lt;title&gt;test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h:form enctype="multipart/form-data"&gt; &lt;input id="uploadify" type="file"/&gt; &lt;h:commandLink action="#{uploadBean.upload}" value="Upload" /&gt; &lt;/h:form&gt; &lt;/body&gt; &lt;/html&gt; &lt;/f:view&gt; &lt;/jsp:root&gt; </code></pre> <p>I am using Uploadify here.</p> <p>I am having two issues:</p> <ul> <li><p>The <code>List&lt;FileItem&gt; fileFields</code> of the <code>upload</code> method is sometime returning <code>null</code>, sometime showing the list. I am unable to find the reason. I have tried to get the <code>HttpSession</code> from the <code>action</code> method by <code>FacesContext.getCurrentInstance().getExternalContext().getSession(false)</code> and then called <code>getAttribute()</code> upon it, that is also always returning <code>null</code>.</p></li> <li><p>If I set 'auto': false, that is the file upload will launch after calling <code>upload();</code> method and modify the <code>&lt;h:commandLink/&gt;</code> as: <code>&lt;h:commandLink action="#{uploadBean.upload}" value="Upload" onclick="upload();"/&gt;</code> then I am getting exception, which is:</p> <pre><code>org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. EOF after reading only: '2392369' of: '11626364' promised bytes, out of which at least: '0' were already buffered at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:367) at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126) at com.edfx.massupload.servlet.UploadServlet.doPost(UploadServlet.java:33) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300) at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56) at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119) at java.security.AccessController.doPrivileged(Native Method) at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315) at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:442) at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103) at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171) at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56) at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:139) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56) at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209) at weblogic.work.ExecuteThread.run(ExecuteThread.java:178) </code></pre></li> </ul> <p>And also in this case the <code>action</code> method is executing before the servlet get executed.</p> <p>How can I solve these two issues?</p> <h2>PS</h2> <p>I need to modify the uploadify.js to set the correct path of the swf file and changed the css for the cancel-button. I have placed the whole directory of the uploadify inside Web-Content.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload