This is an addition to the JSF Visual Web JavaServer Faces in NetBeans Tutorial. For this information to be useful to you you will have to have a JSF Visual Web JavaServer Faces project created. To create the project please refer to the earlier blog. This is the project I will be working with in this tutorial. 

Empty Table

This is what you would do to start with most of the components in JSF. First open Page1.jsp and you will see the Design selected with the nice grid.

http://weblogs.java.net/blog/ddevore/openPage1.jpg

The next step is to select the Table from the Palette and click in the Designer. At this point you will have a page that looks like this.

http://weblogs.java.net/blog/ddevore/defaultTable.jpg

If you run the project at this point you will get a page that looks just like the Designer above. This is because the default table data object DefaultTableDataProvider provides some data by default. The next step is to put some data into the table that is not simply the default. 

Database data in Table

For this part you will need a database connection defined, please check here to create a connection. Once the database is defined open the page designer with the table in it and select the Services tab. For this tutorial I have a database named JSFTutorial in MySQL with a table named address.

http://weblogs.java.net/blog/ddevore/tableBefore.jpg

I will be using the address table, since it is the only table I currently have defined. To bind the JSF table to the address table simply drag and drop the table from the Services tab to the JSF table in the designer. You will now be asked to choose a target, select table1. Once do this you will see the table change to reflect the same number of rows as the address table with the same names as the columns.

http://weblogs.java.net/blog/ddevore/tableAfter.jpg

That is all there is to binding a database to a JSF Table in NetBeans 6.0.

You can now change the column names and the table name by simply clicking on them or selecting the JSP tab of Page1 and change the headerText attributes. You can also select the table and check out the properties and see what they do, pagination is really cool. Next time I will discuss how to use different types of data for the table.