title: JSF PrimeFaces inputText inside dataTable
body: <p><em>JSF-2.0, Mojarra 2.1.19, PrimeFaces 3.4.1</em></p>
  
  <p><em><strong>Summary of the problem</strong>: Have a <code>p:inputText</code> inside <code>p:dataTable</code> and inputText action fired by <code>p:remoteCommand</code> which passes the dataTable row index as a parameter with <code>f:setPropertyActionListener</code>. But it always passes the last row of the dataTable, not the index of the row which includes currently clicked <code>p:inputText</code>.</em></p>
  
  <hr>
  
  <p>As it can be seen from my previous questions, I am trying to use <code>p:inputText</code> as a comment taker for a status like in Facebook or etc. Implementation includes a <code>p:dataTable</code>. It's rows represents each status. Seems like:</p>
  
  <pre><code>&lt;p:dataTable id="dataTable" value="#{statusBean.statusList}" var="status"
                       rowIndexVar="indexStatusList"&gt;
      &lt;p:column&gt;
          &lt;p:panel id="statusRepeatPanel"&gt;
              &lt;p:remoteCommand name="test" action="#{statusBean.insertComment}"
                  update="statusRepeatPanel"&gt;
                  &lt;f:setPropertyActionListener 
                      target="#{statusBean.indexStatusList}"
                      value="#{indexStatusList}"&gt;
                  &lt;/f:setPropertyActionListener&gt;
              &lt;/p:remoteCommand&gt;
              &lt;p:inputText id="commentInput" value="#{statusBean.newComment}"
                  onkeypress="if (event.keyCode == 13) { test(); return false; }"&gt;
              &lt;/p:inputText&gt;
          &lt;/p:panel&gt;
      &lt;/p:column&gt;
  &lt;/p:dataTable&gt;
  </code></pre>
  
  <p>Upper code says when the press enter key, fire <code>p:remoteCommand</code> which calls the insert method of the managed bean.</p>
  
  <pre><code>@ManagedBean
  @ViewScoped
  public class StatusBean {
      List&lt;Status&gt; statusList = new ArrayList&lt;Status&gt;();
      public int indexStatusList;
      public String newComment
      //getters and setters
      public void insertComment() {
          long statusID = findStatusID(statusList.get(indexStatusList));
          statusDao.insert(this.newComment,statusID)
      }
  </code></pre>
  
  <p>Let's debug together; assuming there are <em>three</em> statuses shown in the <code>p:dataTable</code>, click in the <code>p:inputText</code> which in the <em>second</em> status(index of 1), type "relax" and press the enter key.</p>
  
  <p>In the debug console, it correctly shows "relax", but it finds the wrong status because <code>indexStatusList</code> has the value of 2 which belongs <strong>the last status</strong> in the <code>p:statusList</code>. It must be 1 which is the index of <code>p:inputText</code> that clicked on the dataTable row.           </p>
  
  <p>I think problem is about <code>p:remoteCommand</code> which takes the last index on the screen.</p>
  
  <hr>
  
  <p><strong>How it works?</strong></p>
  
  <p>Let's imagine there is a <code>p:commandLink</code> instead of <code>p:remoteCommand</code> and <code>p:inputText</code>:</p>
  
  <pre><code>&lt;p:commandLink action=#{statusBean.insertComment&gt;
        &lt;f:setPropertyActionListener target="#{statusBean.indexStatusList}"
            value="#{indexStatusList}"&gt;&lt;/f:setPropertyActionListener&gt;
  </code></pre>
  
  <p>This component successfully passes the <code>indexStatusList</code> as currently clicked one.</p>