Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As Kai rightfully pointed out in <a href="https://stackoverflow.com/a/19381134/">his answer</a> on the current question, the problem is caused by the <code>NativeFileUploadDecoder</code> as used by <code>FileUploadRenderer</code> not checking whether the request is a <code>multipart/form-data</code> request or not. This will cause trouble when the component is present in a form on which a "regular" ajax request is being submitted. The <code>CommonsFileUploadDecoder</code> checks that correctly and that's why it works correctly in JSF 2.1 which didn't have a native file upload parser yet. </p> <p>His solution of workarounding this with a custom renderer is in the right direction, however the approach is quite clumsy. There's in this particular case absolutely no need of copypasting the whole class consisting more than 200 lines just to add a few more lines. Instead, just extend exactly that class and override exactly the method with an if check before delegating to the super as follows:</p> <pre><code>package com.example; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import org.primefaces.component.fileupload.FileUploadRenderer; public class MyFileUploadRenderer extends FileUploadRenderer { @Override public void decode(FacesContext context, UIComponent component) { if (context.getExternalContext().getRequestContentType().toLowerCase().startsWith("multipart/")) { super.decode(context, component); } } } </code></pre> <p>That's it (keep that <code>&lt;renderer-kit&gt;</code> entry in <code>faces-config.xml</code> though). There's no point of continuing the decode if the request isn't a <code>multipart</code> request. The file parts wouldn't be available anyway (and there's also no point of casting back to <code>javax.servlet.*</code> API when the same functionality is readily available via <code>ExternalContext</code>).</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.
    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.
 

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