Search database using JSF

Asked

Viewed 722 times

1

I am programming an application in JSF, my application can do the function of Record and Change without any problem, but as I am using Java web technology now I am finding a certain difficulty in performing a search and bring the data to a Datatable, someone would have something for me to base myself on to perform such an operation?

1 answer

4


a data table intera over a list. The value of the data table has to be a return list in the query to the bank. and the var attribute is each object in this list and can thus 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

  • It is not easier to return the ResultSet to the dataTable?

  • No Patrick, the resultset is not a list and the objects it returns are not pojos. You don’t have getName example on the return of a resultset. times that transform resultset and objects.

  • If I’m not mistaken, the component dataGrid of Primefaces allows this association, with ResultSet.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.