Search bank using JSF

1

I'm programming an application in JSF, my application manages to do Record and Change with no problem, however as I'm using Java web technology I'm now finding it rather difficult to perform a search and bring the data to a DataTable , would anyone have something that I can rely on to perform such an operation?

    
asked by anonymous 30.09.2014 / 12:23

1 answer

4

A data table interacts over a list. The value of the data table has to be a return list in the query to the database. and the var attribute is every object in that list so you can access its properties.

Example:

Java

class CarrinhoCompraBean { 
  public List<Item> getItems {
    List<Item> items = consultaBanco(idCarrinho);
    return items;
  }
  public static class Item { 
    // ...
  }
}

And in your template, Html

<h:dataTable id="table1" value="#{carrinhoCompraBean.items}" var="item" >
    <h:column>
        <f:facet name="header">
            <h:outputText value="Item" />
        </f:facet>
        <h:outputText value="#{item.nome}" />
    </h:column>
    <h:column>
        <f:facet name="header">
            <h:outputText value="Preço" />
        </f:facet>
        <h:outputText value="#{item.preco}" />
    </h:column>
</h:dataTable>

javadoc dataTable
datatable primefaces

    
30.09.2014 / 13:19