0

im having a problem where i have printed out Snowboards in a datatable from a ArrayList. The problem is happening when i have a button that will be sent to a method and for now just system out it. When the button is clicked i get all the ids from the arraylist instead of just the specific one.

index.xhtml

<h:dataTable value="#{snowboardBean.snowList}" var="list">
                <h:column>
                    ID: #{list.id}<br></br>
                    Product Name: #{list.productName}<br></br>
                    Brand Name: #{list.brandName} <br></br>

                    <ui:param name="listID" value="#{list.id}" />

                    <h:button value="Test" onclick="#{snowboardBean.forwardId(listID)}" />
                </h:column>
            </h:dataTable>

ForwardId() in the bean

public void forwardId(String productId){
    System.out.println("ForwardID");
    this.productId = productId;
    System.out.println(productId);
    System.out.println(this.productId);
}

Output like this after one click: ForwardID 1 ForwardID 2

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Albin Åberg
  • 39
  • 1
  • 8
  • 1
    There are some strange points in your code. I remember that onclick event in is "Javascript code executed when a pointer button is clicked over this element." – tam nguyen Feb 02 '17 at 16:27
  • Don't quite get what you mean. The thing is the code is running and i get output but i get output from all IDs in the arraylist, not the specific one that want. And what are the other strange points that you mentioned? – Albin Åberg Feb 02 '17 at 16:31
  • You can replace to – tam nguyen Feb 02 '17 at 16:49

1 Answers1

0

In your above XHTML you need not to create an param to send the id. Rather just replace you XHTML like below:

<h:dataTable value="#{snowboardBean.snowList}" var="list">
   <h:column>
      ID: #{list.id}<br></br>
      Product Name: #{list.productName}<br></br>
      Brand Name: #{list.brandName} <br></br>
      <h:commandButton value="Test" action="#{snowboardBean.forwardId(list.idD)}" />
   </h:column>
</h:dataTable>
Gaurav Jeswani
  • 4,410
  • 6
  • 26
  • 47