title: JSF Action Method not being called
body: <p>I have a JSF view with a Primefaces data table and a command button insite it, as fallows:</p>
  <pre><code>&lt;p:messages id=&quot;statusMessages&quot; showDetail=&quot;true&quot; /&gt;
      &lt;h:form id=&quot;listForm&quot;&gt;
          &lt;p:panel header=&quot;Wellsite List&quot;&gt;
              &lt;br /&gt;
              &lt;h:outputLabel value=&quot;Welcome, #{wellsiteController.loggedUser.login}&quot; /&gt;
              &lt;br /&gt;
              &lt;br /&gt;
              
              &lt;p:dataTable id=&quot;dataTable&quot; var=&quot;wellsite&quot; value=&quot;#{wellsiteController.wellsiteDataTableModel}&quot;
                           paginator=&quot;true&quot; rows=&quot;10&quot; selection=&quot;#{wellsiteController.wellsite}&quot;&gt;
  
                  &lt;p:column selectionMode=&quot;single&quot; style=&quot;width:18px&quot; id=&quot;radioSelect&quot; /&gt;
  
                  &lt;p:column sortBy=&quot;#{wellsite.reference}&quot; headerText=&quot;Wellsite ID&quot;&gt;
                      &lt;h:outputText value=&quot;#{wellsite.reference}&quot; /&gt;
                  &lt;/p:column&gt;
  
                  &lt;p:column headerText=&quot;Allowed Groups&quot;&gt;
                      &lt;h:outputText value=&quot;#{wellsite.allowedGroups.toString()}&quot; /&gt;
                  &lt;/p:column&gt;
  
                  &lt;f:facet name=&quot;footer&quot;&gt;
                      &lt;h:panelGrid columns=&quot;3&quot;&gt;
                          &lt;p:commandButton id=&quot;addWellsite&quot; value=&quot;Add New Wellsite&quot; icon=&quot;ui-icon-flag&quot; ajax=&quot;false&quot; action=&quot;#{wellsiteController.showAddWellsite}&quot;/&gt;
                          &lt;p:commandButton id=&quot;editWellsite&quot; value=&quot;Edit Selected Wellsite&quot; icon=&quot;ui-icon-wrench&quot; ajax=&quot;false&quot; action=&quot;#{wellsiteController.showEditWellsite}&quot;/&gt;
  
                          &lt;p:commandButton id=&quot;deleteWellsiteButton&quot; value=&quot;Remove Selected Wellsite&quot; icon=&quot;ui-icon-trash&quot; onclick=&quot;confirmation.show()&quot; type=&quot;button&quot;/&gt;
                           
                      &lt;/h:panelGrid&gt;
                  &lt;/f:facet&gt;
              &lt;/p:dataTable&gt;
              &lt;p:spacer height=&quot;20&quot; /&gt;
          &lt;/p:panel&gt;
          &lt;p:confirmDialog id=&quot;confirmDialog&quot; message=&quot;Are you sure you want to remove the selected Wellsite along with all it's data?&quot; header=&quot;Confirmation&quot; severity=&quot;alert&quot; widgetVar=&quot;confirmation&quot;&gt;  
              &lt;p:commandButton id=&quot;confirm&quot; value=&quot;Yes&quot; ajax=&quot;false&quot; oncomplete=&quot;confirmation.hide()&quot; action=&quot;#{wellsiteController.deleteWellsite}&quot; /&gt;
              &lt;p:commandButton id=&quot;decline&quot; value=&quot;Cancel&quot; onclick=&quot;confirmation.hide()&quot; type=&quot;button&quot; /&gt;   
  
          &lt;/p:confirmDialog&gt;
      &lt;/h:form&gt;
  </code></pre>
  <p>And here's the controller:</p>
  <pre><code>@ManagedBean(name = &quot;wellsiteController&quot;)
  @RequestScoped
  public class WellsiteController implements Serializable {
  private static final long serialVersionUID = 1L;
  
  @ManagedProperty(&quot;#{wellsiteDao}&quot;)
  private WellsiteDao wellsiteDao;
  
  @ManagedProperty(&quot;#{userDao}&quot;)
  private UserDao userDao;
  
  @ManagedProperty(&quot;#{groupDao}&quot;)
  private GroupDao groupDao;
  
  @ManagedProperty(&quot;#{userController.loggedUser}&quot;)
  private UserEnt loggedUser;
  
  private WellsiteEnt wellsite;
  private List&lt;WellsiteEnt&gt; wellsiteList;
  DualListModel&lt;GroupEnt&gt; pickGroupsModel;
  
  public WellsiteController(){
  }
  
  @PostConstruct
  public void build(){
      wellsite = new WellsiteEnt();
      wellsite.setAllowedGroups(new ArrayList&lt;GroupEnt&gt;());
  }
  
  /*some getters &amp; setters*/
  
  public WellsiteDataTableModel getWellsiteDataTableModel(){
      return new WellsiteDataTableModel(getWellsiteList());
  }
  
  public void setPickGroupsModel(DualListModel&lt;GroupEnt&gt; model){
      pickGroupsModel = model;
  }
  
  public DualListModel&lt;GroupEnt&gt; getPickGroupsModel() {
      if(pickGroupsModel == null){
          List&lt;GroupEnt&gt; allGroups = groupDao.getAll();
          List&lt;GroupEnt&gt; currentGroups = wellsite.getAllowedGroups();
          for(GroupEnt g : currentGroups){
              allGroups.remove(g);
          }
          pickGroupsModel = new DualListModel&lt;GroupEnt&gt;(allGroups, currentGroups);
      }
      return pickGroupsModel;
  }
  
  public String listWellsites(){
      getWellsiteList();
      return &quot;listWellsites&quot;;
  }
  
  public String showAddWellsite(){
      FacesContext context = FacesContext.getCurrentInstance();
      setWellsite(new WellsiteEnt());
      wellsite.setAllowedGroups(new ArrayList&lt;GroupEnt&gt;());
      pickGroupsModel = null;
      context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
                                              &quot;Fields annotated with a ' * ' are mandatory&quot;,&quot;&quot;));
      return &quot;addWellsite&quot;;
  }
  
  public String addWellsite(){
      FacesContext context = FacesContext.getCurrentInstance();
      
      wellsite.setDate(new Date());
      wellsite.setLastUpdate(wellsite.getDate());
      try {
          wellsiteDao.addWell(wellsite);
          
          for(GroupEnt g : pickGroupsModel.getTarget()){
              GroupEnt group = groupDao.getOne(g.getGroupId());
              group.getGroupWellsites().add(wellsite);
              groupDao.update(group);
          }
          return listWellsites();
          
      } catch (Exception ex) {
          Logger.getLogger(WellsiteController.class.getName()).log(Level.SEVERE, null, ex);
          context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                              ex.getMessage(),&quot;&quot;));
          return null;
      }
  }
  }
  </code></pre>
  <p>This view gets rendered correctly. The datatable and buttons looks fine. The problem is that when first i click the &quot;addWellsite&quot; commandButton, nothing happens. The page just seems to refresh. If i click it again, as exception happens:</p>
  <p><code>java.lang.NumberFormatException: For input string: &quot;null&quot;</code></p>
  <p>Using a debugger, i found out that the &quot;addWellsite&quot;'s action is NOT called the first time, and so, not outcome is generated (thus, the page refresh).</p>
  <p>The exception is probably comming from the lack of initialization in the current or the target views (since both view are displayed from action methods that were not called in the page refresh)</p>
  <p>The question is: <strong>WHY the action method is not called the first time?</strong></p>
  <p>As from <a href="https://stackoverflow.com/questions/2118656/hcommandlink-is-not-being-invoked/2120183#2120183">this answer</a>:</p>
  <blockquote>
  <p>Whenever an <code>UICommand</code> component fails to invoke the associated action, verify the following:</p>
  <ol>
  <li><code>UICommand</code> components must be placed inside an <code>UIForm</code> component (e.g. <code>h:form</code>).</li>
  </ol>
  </blockquote>
  <p>I do have a h:form</p>
  <blockquote>
  <ol start="2">
  <li>You cannot <strong>nest</strong> multiple <code>UIForm</code> components in each other (watch out with include files!).</li>
  </ol>
  </blockquote>
  <p>There's only one.</p>
  <blockquote>
  <ol start="3">
  <li>No validation/conversion error should have been occurred (use <code>h:messages</code> to get them all).</li>
  </ol>
  </blockquote>
  <p>I have a h:messages that does not display any error.</p>
  <blockquote>
  <ol start="4">
  <li>If <code>UICommand</code> components are placed inside an <code>UIData</code> component, ensure that exactly the same <code>DataModel</code> (the object behind the <code>UIData</code>'s <code>value</code> attribute) is preserved.</li>
  </ol>
  </blockquote>
  <p>The commandButton is inside the dataTable, but the target view does not need the dataModel. As my controller code shows, the object is built as the view tries to retrive it. The next request is not using this dataTable, to i do not handle it anymore.</p>
  <blockquote>
  <ol start="5">
  <li>The <code>rendered</code> and <code>disabled</code> attributes of the component and all of the parent components should not evaluate to <code>false</code> during apply request values phase.</li>
  </ol>
  </blockquote>
  <p>There's no <code>rendered</code> or <code>disbled</code> attributes.</p>
  <blockquote>
  <ol start="6">
  <li>Be sure that no <code>PhaseListener</code> or any <code>EventListener</code> in the request-response chain has changed the JSF lifecycle to skip the invoke action phase.</li>
  </ol>
  </blockquote>
  <p>No phaseListener is defined.</p>
  <blockquote>
  <ol start="7">
  <li>Be sure that no <code>Filter</code> or <code>Servlet</code> in the same request-response chain has blocked the request fo the <code>FacesServlet</code> somehow.</li>
  </ol>
  </blockquote>
  <p>No other Servlet is defined. I don't even know what a Filter is.</p>
  <p><strong>WHY the action method is not called the first time?</strong></p>