title: PrimeFaces 3.5 File Upload in Datatable
body: <p>I am trying to use <code>&lt;p:cellEditor&gt;</code> for <code>&lt;p:fileUpload&gt;</code>. When I tried to upload a file, it comes as <code>null</code>. How is this caused and how can I solve it?</p>
  
  <p>I'm using PrimeFaces 3.5 and JSF 2.0.</p>
  
  <p>Here is the view:</p>
  
  <pre><code>&lt;p:dataTable id="question" var="question" value="#{editor.questions}" editable="true" widgetVar="carsTable" resizableColumns="true"&gt;
      &lt;f:facet name="header"&gt;Economic&lt;/f:facet&gt;
      &lt;p:ajax event="rowEdit" listener="#{editor.onEdit}"  /&gt;
      &lt;p:ajax event="rowToggle" listener="#{editor.onRowToggle}" /&gt;
  
      &lt;p:column style="width:6%"&gt;
          &lt;p:rowEditor /&gt;
      &lt;/p:column&gt;
  
      &lt;p:column style="width:2%"&gt;
          &lt;p:rowToggler /&gt;
      &lt;/p:column&gt;
  
      &lt;p:column headerText="Performance Indicator" style="width:25%"&gt;
          &lt;h:outputText value="#{question.performanceIndicator}" title="#{question.performanceIndicator}"/&gt;
      &lt;/p:column&gt;
  
      &lt;p:column headerText="Description" style="heigh:200px;width:200px"&gt;
          &lt;h:outputText value="#{question.description}" /&gt;
      &lt;/p:column&gt;
  
      &lt;p:column headerText="CSR Label" style="width:25%"&gt;
          &lt;h:outputText value="#{question.csrLabel}" /&gt;
      &lt;/p:column&gt;
  
      &lt;p:column headerText="Response" style="width:25%"&gt;
          &lt;p:cellEditor&gt;
              &lt;f:facet name="output"&gt;
                  &lt;h:outputText value="#{question.response}" /&gt;
              &lt;/f:facet&gt;
              &lt;f:facet name="input"&gt;
                  &lt;h:selectOneMenu value="#{question.response}" style="width:100%"&gt;
                      &lt;f:selectItem value="#{tableBean.manufacturers}"  itemLabel="Yes" itemValue="Y" /&gt;
                      &lt;f:selectItem value="#{tableBean.manufacturers}"  itemLabel="No" itemValue="N" /&gt;
                      &lt;f:selectItem value="#{tableBean.manufacturers}"  itemLabel="Partial" itemValue="P" /&gt;
                  &lt;/h:selectOneMenu&gt;
              &lt;/f:facet&gt;
          &lt;/p:cellEditor&gt;
      &lt;/p:column&gt;
  
      &lt;p:column headerText="File" style="width:25%"&gt;
          &lt;p:cellEditor&gt;
              &lt;f:facet name="output"&gt;
                  &lt;h:outputText value="#{question.file.fileName}" /&gt;
              &lt;/f:facet&gt;
              &lt;f:facet name="input"&gt;
                  &lt;p:fileUpload value="#{question.file}" mode="simple"/&gt;
              &lt;/f:facet&gt;
          &lt;/p:cellEditor&gt;
      &lt;/p:column&gt;
  
      &lt;p:rowExpansion&gt;
          &lt;h:panelGrid id="display" columns="2"&gt;
              &lt;h:outputText id="model" value="#{question.description}" /&gt;
          &lt;/h:panelGrid&gt;
      &lt;/p:rowExpansion&gt;
  &lt;/p:dataTable&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>Update</strong>: Yes it's inside a <code>&lt;h:form&gt;</code>.</p>
  
  <p>Here is the backing bean:</p>
  
  <pre><code>package org.zicon.web.jsf;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.logging.Logger;
  
  import javax.faces.application.FacesMessage;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.RequestScoped;
  import javax.faces.bean.ViewScoped;
  import javax.faces.context.FacesContext;
  import javax.faces.event.ActionEvent;
  
  import org.primefaces.event.CellEditEvent;
  import org.primefaces.event.FlowEvent;
  import org.primefaces.event.RowEditEvent;
  import org.primefaces.event.ToggleEvent;
  import org.primefaces.model.UploadedFile;
  import org.springframework.context.annotation.Scope;
  import org.springframework.stereotype.Component;
  import org.zicon.domain.GRI;
  import org.zicon.domain.User;
  
  
  
  
  @ManagedBean(name="userWizard")
  @RequestScoped
  public class UserWizard {
  
  
      private List&lt;GRI&gt; questions;
          private User user = new User();
  
          private boolean skip;
  
          private String effect = "fade";
  
          private static Logger logger = Logger.getLogger(UserWizard.class.getName());
  
          public User getUser() {
                  return user;
          }
  
          public void setUser(User user) {
                  this.user = user;
          }
  
          public void save(ActionEvent actionEvent) {
                  //Persist user
  
              for(GRI gri:questions)
              {
                  System.out.println("Response"+gri.getResponse());
                  System.out.println("File Name"+gri.getFile().getFileName());
  
              }
  
                  FacesMessage msg = new FacesMessage("Successful", "Welcome :" + user.getFirstname());
                  FacesContext.getCurrentInstance().addMessage(null, msg);
          }
  
          public String getEffect() {
                  return effect;
          }
  
          public void setEffect(String effect) {
                  this.effect = effect;
          }
  
          public boolean isSkip() {
                  return skip;
          }
  
          public void setSkip(boolean skip) {
                  this.skip = skip;
          }
  
          public String onFlowProcess(FlowEvent event) {
                  logger.info("Current wizard step:" + event.getOldStep());
                  logger.info("Next step:" + event.getNewStep());
  
                  if(skip)
                          return "confirm";
                  else
                          return event.getNewStep();
          }
  
          public UserWizard() {
              questions=new ArrayList&lt;GRI&gt;();
                  GRI gri=new GRI();
                  gri.setPerformanceIndicator("EC1");
                  gri.setDescription("Direct economic value generated and distributed, including " +
                          "revenues, operating costs, employee compensation, donations and other community investments, " +
                          "retained earnings, and payments to capital providers and governments.");
                  gri.setCsrLabel("3.1");
  
                  questions.add(gri);
  
                  GRI gri1=new GRI();
                  gri1.setPerformanceIndicator("EC2");
                  gri1.setDescription("Financial implications and other risks and opportunities for the organization's activities due to climate change" );
  
  
                  questions.add(gri1);
  
                  GRI gri2=new GRI();
                  gri2.setPerformanceIndicator("EC1");
                  gri2.setDescription("Direct economic value generated and distributed, including " +
                          "revenues, operating costs, employee compensation, donations and other community investments, " +
                          "retained earnings, and payments to capital providers and governments.");
                  gri2.setCsrLabel("3.1");
  
                  questions.add(gri2);
  
                  GRI gri3=new GRI();
                  gri3.setPerformanceIndicator("EC3");
                  gri3.setDescription("Coverage of the organization's defined benefit plan obligations. ");
  
  
                  questions.add(gri3);
  
                  GRI gri4=new GRI();
                  gri4.setPerformanceIndicator("EC4");
                  gri4.setDescription("Significant financial assistance received from government. ");
  
  
                  questions.add(gri4);
  
                  GRI gri5=new GRI();
                  gri5.setPerformanceIndicator("EC5");
                  gri5.setDescription("Range of ratios of standard entry level wage compared to local minimum wage at significant" +
                          " locations of operation.");
                  gri5.setCsrLabel("1.2");
  
                  questions.add(gri5);
  
  
  
          }
  
            public void onCellEdit(CellEditEvent event) {
                  Object oldValue = event.getOldValue();
                  Object newValue = event.getNewValue();
  
                  if(newValue != null &amp;&amp; !newValue.equals(oldValue)) {
                      FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
                      FacesContext.getCurrentInstance().addMessage(null, msg);
                  }
              }
  
          public List&lt;GRI&gt; getQuestions() {
              return questions;
          }
  
          public void setQuestions(List&lt;GRI&gt; questions) {
              this.questions = questions;
          }
  
          public void onRowToggle(ToggleEvent event) {
              FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
                                                  "Row State " + event.getVisibility(),
                                                  "Model:" );
  
              FacesContext.getCurrentInstance().addMessage(null, msg);
          }
  
           public void onEdit(RowEditEvent event) {
                  FacesMessage msg = new FacesMessage("Question Edited", ((GRI) event.getObject()).getResponse());
  
                  GRI gri=((GRI) event.getObject());
  
                  FacesContext.getCurrentInstance().addMessage(null, msg);
              }
  
           private UploadedFile file;
  
              public UploadedFile getFile() {
                  return file;
              }
  
              public void setFile(UploadedFile file) {
                  this.file = file;
              }
  
              public void upload() {
                  if(file != null) {
                      FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
                      FacesContext.getCurrentInstance().addMessage(null, msg);
                  }
              }
  }
  </code></pre>