4 Replies Latest reply on Jan 4, 2008 10:07 AM by Felix Khazin

    Retreiving data based on displayed data

    Felix Khazin Newbie

      Hi,

      I'm not sure if I am doing this correctly so any help would be appreciated. Here is the situation: I have a page that displays a particular Customer. Underneath that Customer i'd like to list all the orders.

      I've created a bean with the following method:

      public List<CustomerProduct> customerProductListByCustomer(Customer customer)


      I have a rich:datatable on the view that calls this method and fills in the table. Problem is I need to use this method to determine if the table should be rendered. So I have the following in the view:

      <h:outputText value="No Customer Products Exist." rendered="#{empty customerProductList.customerProductListByCustomer(customerHome.instance)}"/>
       <rich:dataTable id="customerProductList" var="customerProduct"
       value="#{customerProductList.customerProductListByCustomer(customerHome.instance)}"
       rendered="#{not empty customerProductList.customerProductListByCustomer(customerHome.instance)}">
       <rich:column>
       <f:facet name="header">Name</f:facet>
       #{customerProduct.productInstanceName}
       </rich:column>
       </rich:dataTable>


      The problem with this approach is that now Hibernate queries my database 3 times. Twice to check if there is data to render, and once to populate the table.

      My question is, is my method the standard way to do this? I'd rather just have a bean with an @Out that I can use to check if is empty and use to populate the datatable, but then I can't pass it an argument (in this case the customer). Any suggestions?

      Thanks,
      Felix