Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your problem is caused by a combination of those 2 causes:</p> <ol> <li>The bean is request scoped.</li> <li>The <code>&lt;p:fileUpload&gt;</code> is running in "advanced mode" (with browse, upload and cancel buttons).</li> </ol> <p>A request scoped bean has a lifetime of exactly one HTTP request. Uploading a file using <code>&lt;p:fileUpload&gt;</code> button accounts as one HTTP request. Submitting the form accounts as another HTTP request, with its own brand new instance of the bean. You should have noticed it by <code>user.getImage()</code> being null/empty during <code>em.persist()</code> while doing a simple debug.</p> <p>In order to get it to work, you need to put the bean in the view scope. This way the bean will live as long as you're interacting with the same view.</p> <pre><code>@ManagedBean @ViewScoped public class UserUpdateBean {} </code></pre> <p><em>(or with <code>&lt;managed-bean-scope&gt;view</code> when using the old fashioned XML config approach)</em></p> <p>An alternative is to set <code>&lt;p:fileUpload&gt;</code> to "simple mode" so that it comes with only a browse button and get uploaded only when you actually submit the form. This way the uploaded file will be set during the <strong>same</strong> HTTP request as when the form is submitted.</p> <pre><code>&lt;p:fileUpload ... mode="simple" /&gt; </code></pre> <h3>See also:</h3> <ul> <li><a href="https://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope">How to choose the right bean scope?</a></li> </ul>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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