Java Reference
In-Depth Information
Now what we need to do is display all customers in the database in the table. The
woodstock table component has the concept of data providers ; data providers
provide data for the table to populate itself. There are several data providers
available; the easiest one to use in visual web JSF is the Object Array Data Provider ,
since we can simply graphically bind an object array property to a table, and an
object array data provider with all the appropriate values is generated in the
code automatically.
dataprovider/index.html for more information about the different
data providers.
The CustomerFacade session bean we generated when implementing the data
access layer of our application contains a method named findAll() that returns
all customers in the database, this method returns the customers as a List . In order
for us to be able to take advantage of NetBeans visual web JSF functionality, we
need to convert the generated values into an array of Customer objects. It is a good
idea to keep these objects in the session, that way they can be reused across HTTP
requests. Therefore we will add a method to the generated SessionBean1 managed
bean to invoke the findAll() method, convert the returned list into an array of
customers, and return this array. The following code listing illustrates the necessary
modifications to .
package com.ensode.customermanagement.managedbean;
//imports omitted for brevity
public class SessionBean1 extends AbstractSessionBean {
private CustomerFacadeLocal customerDAO;
private Customer[] customerArray;
//Other methods omitted for brevity
public Customer[] getCustomerArray() {
List<Customer> customerList = customerDAO.findAll();
if (customerList != null) {
customerArray =
customerList.toArray(new Customer[0]);
} else {
customerArray = null;
return customerArray;
Search WWH ::

Custom Search