title: Passing parameters to a bean method from a datatable within a view/page in JSF 2.0
body: <p>I have a page with a datatable that populates from a list. The list has many ids, which I need to pass to a bean method and perform a database operation.I am using a commandButton's rendered attribute to make a call to the bean method (findInfo()). I need to pass the ids (myBean.testList.id) one at a time from the list to this bean method so that I get the boolean back. First of, I am not sure how to pass the id (to the findInfo method in my bean), secondly if I use  tag, I end up sending just a single ID. Could anyone please suggest me a solution. I tried doing it with the codes as below.</p>
  
  <p>My Bean</p>
  
  <pre><code>@ManagedBean(name="myBean")
  public class MyBean(){
  
    public boolean findInfo(Integer indId){
      boolean var = dataProvider.isIdPresent(indId); // database operation
      if (var)
          return true;
      else 
          return false;
    }
  }
  </code></pre>
  
  <p>xhtml page</p>
  
  <pre><code>&lt;h:dataTable value="#{myBean.testList}" var="t" &gt;
  
    &lt;h:column&gt;
      &lt;f:facet name="header"&gt;
          &lt;h:outputText value="Actions" /&gt;
      &lt;/f:facet&gt;
  
      &lt;h:commandButton value = "Add"
      action = "#{someBean.loadReport}"
      rendered = "#{myBean.findInfo() == false}"/&gt;
  
      &lt;h:commandButton value = "View"
      action = "#{someBean.loadReport}"
      rendered = "#{myBean.findInfo() == true}"/&gt;
  
  &lt;/h:column&gt;
  &lt;h:column&gt;
  ...
  &lt;/h:column&gt;
  &lt;/h:dataTable&gt;
  </code></pre>
  
  <p><strong>UPDATE:</strong>
  I tried to follow the answer that BalusC's explained (that kolossus posted), I end up passing the id as null in f:param. Any suggestions. My updated code:</p>
  
  <pre><code>&lt;h:dataTable value="#{myBean.testList}" var="t" &gt;
  
  &lt;h:column&gt;
      &lt;f:facet name="header"&gt;
          &lt;h:outputText value="Actions" /&gt;
      &lt;/f:facet&gt;
  
  
      &lt;h:commandButton value = "Add"
      action = "#{someBean.loadReport}"
      rendered = "#{myBean.findInfo() == false}"&gt;
          &lt;f:param name="id" value="#{t.id}" /&gt; 
  
      &lt;/h:commandButton&gt;
  
      &lt;h:commandButton value = "View"
      action = "#{someBean.loadReport}"
      rendered = "#{myBean.findInfo() == true}"&gt;
          &lt;f:param name="id" value="#{t.id}" /&gt; 
      &lt;/h:commandButton&gt;
  
  &lt;/h:column&gt;
  &lt;h:column&gt;
  ...
  &lt;/h:column&gt;
  </code></pre>
  
  <p></p>
  
  <p>My Updated Bean</p>
  
  <pre><code>@ManagedBean(name="myBean")
  @RequestScoped
  public class MyBean(){
  
  @ManagedProperty("#{param.id}")
  private Integer indId;
  
  public boolean findInfo(){
      boolean var = dataProvider.isIndIdPresent(indId);
      if (var)
          return true;
      else 
          return false;
  }
  }
  </code></pre>
  
  <p>Also, I think I cannot use f:ViewParam as I am calling the bean from the data table within the same view.</p>