title: not invoking the setter method in jsf
body: <p>i m working on javas server faces. i have used the User.java class as model ,UserController as controller and index.xhtml,ViewProfile,xhtml as view . i traced the following code and i observed that the setter method set setUploadedFile(UploadedFile file){} not invoking .whereas other two setters are invoking.and it is giving NullPointerException. what is the reason ? i m not getting . Here is the code</p>
  
  <p>UserController.java</p>
  
  <pre><code>@Named("controller")
  @RequestScoped
  
  public class UserController implements Serializable
  {
      private User user=new User();   
  
      public User getUser() {
          return user;
      }
  
      public void setUser(User user) {
          this.user = user;
      }
  
      public String submit() throws IOException ,SQLException ,ClassNotFoundException, InstantiationException, IllegalAccessException
      {
          String fileName = FilenameUtils.getName(user.getUploadedFile().getName());
          byte[] bytes = user.getUploadedFile().getBytes();
          int index=fileName.indexOf('.');
          String extension=fileName.substring(index);
          File file;
          String path;
          path = "C:/Users/";
          if(extension.equalsIgnoreCase(".jpg")||extension.equalsIgnoreCase(".jpeg")||extension.equalsIgnoreCase(".png")||extension.equalsIgnoreCase(".gif")||extension.equalsIgnoreCase(".tif"))
          {
              file=new File(path);      
              if(!file.exists())
              {
                  file.mkdir();                
              }
              path=file+"/"+fileName;
              FileOutputStream outfile=new FileOutputStream(path);           
              outfile.write(bytes);
              outfile.close();  
              PreparedStatement stmt;            
              Connection connection;
              String url="jdbc:mysql://localhost:3306/userprofile";
              Class.forName("com.mysql.jdbc.Driver").newInstance();
              connection = DriverManager.getConnection(url, "root", "mysql"); 
              stmt = connection.prepareStatement("insert into table_profile values('"+user.getUserName()+"','"+user.getUserId()+"','"+path+"')");                                 
              stmt.executeUpdate();
              connection.close(); 
              return "SUCCESS";
          }
          else
          {
              return "fail";
          }              
      }
  }
  </code></pre>
  
  <p>User.java</p>
  
  <pre><code>import org.apache.myfaces.custom.fileupload.UploadedFile;
  
  
  public class User implements java.io.Serializable
  {    
      private String userName;
  
      public String getUserName() {
          return userName;
      }
  
      public void setUserName(String userName) {
          System.out.println("in setter of username");
          this.userName = userName;
      }
  
      private String userId;
  
      public String getUserId() {
          return userId;
      }
  
      public void setUserId(String userId) {
          this.userId = userId;
          System.out.println("in setter of userid");
      }
  
      private UploadedFile uploadedFile;
  
      public UploadedFile getUploadedFile()
      {
          return uploadedFile;
      }
  
      public void setUploadedFile(UploadedFile uploadedFile) 
      {
          this.uploadedFile = uploadedFile;
          System.out.println("in setter of upload");
      }
  }
  </code></pre>
  
  <p>index.xhtml</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:t="http://myfaces.apache.org/tomahawk"&gt;
  
      &lt;h:head&gt;
          &lt;title&gt;Profile Demo&lt;/title&gt;        
      &lt;/h:head&gt;
      &lt;h:body&gt;
  
          &lt;h:form&gt;
              &lt;h:panelGrid columns="2"&gt;
  
                  &lt;h:outputLabel for="userId"&gt;User Id&lt;/h:outputLabel&gt;
                  &lt;h:inputText id="userId" value="#{controller.user.userName}" required="true"&gt;&lt;/h:inputText&gt;
  
                  &lt;h:outputLabel for="username"&gt;Username&lt;/h:outputLabel&gt;
                  &lt;h:inputText id="username" value="#{controller.user.userId}" required="true"&gt;&lt;/h:inputText&gt;
  
                 &lt;h:outputLabel for="photo"&gt;Profile Picture&lt;/h:outputLabel&gt;
                 &lt;t:inputFileUpload value="#{controller.user.uploadedFile}"  required="true"&gt;&lt;/t:inputFileUpload&gt;
  
                 &lt;h:commandButton value="Register" action="#{controller.submit()}"&gt;&lt;/h:commandButton&gt;            
            &lt;/h:panelGrid&gt; 
          &lt;/h:form&gt;
  
      &lt;/h:body&gt; 
  
  &lt;/html&gt;
  </code></pre>