Note that there are some explanatory texts on larger screens.

plurals
  1. PORichface: a4j:mediaOutput, data is 'null'
    primarykey
    data
    text
    <p>I'm getting nullpointer when i try to display an image i upload.</p> <p>I follow the example from: <a href="http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=fileUpload" rel="nofollow">Richfaces Showcase</a></p> <p>Error: <strong>javax.el.ELException: ...[path]... createContent="#{imageBean.paint}": java.lang.NullPointerException</strong> </p> <p>Used source code:</p> <p><strong>ImageBean.java</strong></p> <pre><code>@ManagedBean @SessionScoped public class ImageBean implements Serializable{ private ImageData imageData= new ImageData(); public void listener(FileUploadEvent event) throws Exception { UploadedFile item = event.getUploadedFile(); imageData = new ImageData(); imageData.setName(item.getName()); imageData.setData(item.getData()); } public void paint(OutputStream stream, Object object) throws IOException { stream.write(getFile().getData()); stream.close(); } // getters and setters for file </code></pre> <p><strong>uploadImage.xhtml</strong></p> <pre><code>&lt;h:form&gt; &lt;h:panelGrid columns="2" columnClasses="top,top"&gt; &lt;rich:fileUpload fileUploadListener="#{imageBean.listener}" id="upload" acceptedTypes="jpg, gif, png, bmp" ontyperejected="alert('Only JPG, GIF, PNG and BMP files are accepted');" maxFilesQuantity="1"&gt; &lt;a4j:ajax event="uploadcomplete" execute="@none" render="info" /&gt; &lt;/rich:fileUpload&gt; &lt;h:panelGroup id="info" layout="block"&gt; &lt;rich:panel bodyClass="info"&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="Uploaded Files Info" /&gt; &lt;/f:facet&gt; &lt;h:outputText value="Geen foto beschikbaar" rendered="#{imageBean.size==0}" /&gt; &lt;a4j:mediaOutput element="img" mimeType="image/jpeg" createContent="#{imageBean.paint}" value="#{imageBean.file.name}" style="width:100px; height:100px;" cacheable="false"&gt; &lt;/a4j:mediaOutput&gt; &lt;h:panelGrid columns="2"&gt; &lt;h:outputText value="File Name:" /&gt; &lt;h:outputText value="#{imageBean.file.name}" /&gt; &lt;/h:panelGrid&gt; &lt;/rich:panel&gt; &lt;br /&gt; &lt;/h:panelGroup&gt; &lt;/h:panelGrid&gt; &lt;/h:form&gt; </code></pre> <p>According to my debugger: imageDate gets data in the upload <strong>listener()</strong> but is null in the <strong>paint()</strong></p> <p>My thought would be then that i should put my scope bigger. So I have set it to <strong>@SessionScoped</strong></p> <p><strong>Web.xml</strong>:</p> <pre><code>&lt;context-param&gt; &lt;param-name&gt;createTempFiles&lt;/param-name&gt; &lt;param-value&gt;false&lt;/param-value&gt; &lt;/context-param&gt; </code></pre> <p>I have tried both true and false</p> <p>Using Richfaces: 4.3.2</p>
    singulars
    1. This table or related slice is empty.
    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. 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