title: How To Set A Value To An Object In An (Actionlistener) Save Method?
body: <p>I have an <code>actionListener</code> below that works fine:</p>
  
  <pre><code>&lt;p:commandButton actionListener="#{demandasController.saveNew}" ... /&gt;
  </code></pre>
  
  <p>The <code>saveNew</code> method is:</p>
  
  <pre><code>public void saveNew(ActionEvent event) {
  
      Situacao situacao = new Situacao();
      situacao.setIdSituacao(4);
  
      this.getSelected().setSituacao(situacao);
  
      super.saveNew(event);
  }
  </code></pre>
  
  <p>If I use the code above, it works just fine. But if I try...</p>
  
  <pre><code>public void saveNew(ActionEvent event) {
  
  Situacao situacao = new Situacao();
  
  Date currentDate = new Date();
  
  if (this.getSelected().getDtInicial().after(currentDate)) {
      situacao.setIdSituacao(4);
  } else {
      situacao.setIdSituacao(5);
  }
  
  this.getSelected().setSituacao(situacao);
  
  super.saveNew(event);
  }
  </code></pre>
  
  <p>...it returns a <a href="https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it">NullPointerException</a>. </p>
  
  <p>Does anyone knows why this is happening and/or how can I fix it ?</p>
  
  <p>Thanks in advance.</p>