Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was finally able to figure it out. Commons-fileuploads method <code>parseRequest(httpServletRequest)</code> tries to read the request's inputStream. Since the container already read it, it is empty. So what can be done to solve this? The answer is a bit more complicated than I initially thought it would be. First you will need your own FileUploadFilter which could look like this:</p> <pre><code>public class FileUploadFilter implements Filter { private final static Logger LOGGER = LoggerFactory.getLogger(FileUploadFilter.class); /* * (non-Javadoc) * * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) */ @Override public void init(FilterConfig filterConfig) throws ServletException { } /* * (non-Javadoc) * * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, * javax.servlet.ServletResponse, javax.servlet.FilterChain) */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest httpServletRequest = (HttpServletRequest) request; boolean isMultipart = (httpServletRequest.getContentType() == null) ? false : httpServletRequest.getContentType().toLowerCase().startsWith("multipart/"); if (isMultipart) { MultipartRequest multipartRequest = new MultipartRequest(httpServletRequest); LOGGER.info("File upload request parsed succesfully, continuing with filter chain with a wrapped multipart request"); filterChain.doFilter(multipartRequest, response); } else { filterChain.doFilter(request, response); } } /* * (non-Javadoc) * * @see javax.servlet.Filter#destroy() */ @Override public void destroy() { LOGGER.info("Destroying UploadFilter"); } </code></pre> <p>Next: Register this filter in your web.xml and remove/replace the Primefaces filter. This should look something like this:</p> <pre><code> &lt;filter&gt; &lt;filter-name&gt;FileUpload Filter&lt;/filter-name&gt; &lt;filter-class&gt;&lt;YourPackage&gt;.FileUploadFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;FileUpload Filter&lt;/filter-name&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;/filter-mapping&gt; </code></pre> <p>Unfortunately thats not it. You will need your own MultipartRequest since you have to assemble the list of FileItems by yourself. But Stop. We have to work with the javax.servlet.Part classes which are not compatible with the FileItem. So i wrote a new class which bridges these two. You can find this class here: <a href="http://pastebin.com/JcfAYjey" rel="noreferrer">http://pastebin.com/JcfAYjey</a></p> <p>The last piece of the puzzle is the mentioned MultipartRequest which links the PartItem and the FileUploadFilter. I took this class from the Primefaces-Repository and changed it according to out needs (see <a href="http://pastebin.com/Vc5h2rmJ" rel="noreferrer">http://pastebin.com/Vc5h2rmJ</a>). The difference is between lines 47 and 57.</p> <p>So what do you have to do: 1. Create the three classes FileUploadFilter, MultipartRequest and PartItem 2. Register the FileUploadFilter in your web.xml 3. Enjoy!</p> <p>PLEASE NOTE: This is not intended as a solve-all-problems solution but a merely a direction you may take in further implementations. The MultipartRequest for example will only work for parts with content-type <code>image/*</code>. You may need to change this.</p> <p>Feel free to change the code ;) Hope it helps!</p> <p>EDIT: I forgot to mention one important step. You will additionally need your Own FileIUploadRenderer. The one Primefaces implemented uses an <code>instanceof</code> check to find the MultipartRequest. Since you are now using a different one the import has to be changed. The rest of the class can stay the same (<a href="http://pastebin.com/rDUkPqf6" rel="noreferrer">http://pastebin.com/rDUkPqf6</a>). Don't forget to register it inside of your faces-config.xml :</p> <pre><code>&lt;render-kit&gt; &lt;renderer&gt; &lt;component-family&gt;org.primefaces.component&lt;/component-family&gt; &lt;renderer-type&gt;org.primefaces.component.FileUploadRenderer&lt;/renderer-type&gt; &lt;renderer-class&gt;&lt;YourPackage&gt;.FileUploadRenderer&lt;/renderer-class&gt; &lt;/renderer&gt; &lt;/render-kit&gt; </code></pre>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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