NB 6.0 Visual Web Table Component Binding Enhancements To Use POJOs
Netbeans 5.5.1 Visual Web Table Component allows binding only via Data Providers such as CahcedRowsetDataProvider. While working with Hibernate or JPA or Spring framework, you must be dealing with Plain Old Java Objects (POJOs). If you have List or Array of POJOs, then only way to bind them to the Table Component is by creating ObjectListDataProvider or ObjectArrayDataProvider. Also, due to a bug in Netbeans 5.5.1 Visual Web designtime, you may have to use the work around I explained in one of my earlier blogs - Work around for Object List Data Provider design time problem.
We have changed couple of things in Netbeans 6.0 related to Table Component binding.
Binding Array of POJOs
In order to bind Array of POJOs, first you need to create a property in the backing Page Bean or some other Managed Beans (Ex. SessionBean1), that returns Array (say myArray) of the Specified Object (say MyObject). To create the property
The above would add the code to the Java source as
private MyObject[] myArray;
public MyObject[] getMyArray(){
return myArray;
}
public void setMyArray(MyObject[] myArray){
this.myArray = myArray;
}
Now to bind myArray, compile the project, refresh the designer and bring up the Table Layout. You will find myArray listed in the drop down list as show in the picture below.

Binding List of POJOs
Binding List of POJOs is more or less same as binding arrays with one important difference. In case of Array of POJOs, the Array itself has information about the type of the POJO. However, in case of List of POJOs, the Table Component can not determine the type of the POJO, since List is one of the generic interface in the Collections Framework. In order to solve this problem, Java Generics comes handy. You can specify the type of the POJO, that will be added to the list, to the design system using a parameterized List as shown below. This is really useful if the List will be populated lazily during runtime. Add the myList property to the backing Page Bean
This would add the code to the Java source as
private List<MyObject> myList;
public List<MyObject> getMyList(){
return myList;
}
public void setMyList(List<MyObject> myArray){
this.myList = myList;
}
Similar to binding Array of POJOs, bring up the Table Layout and myList will be listed in the drop down list as show in the picture below. Don't forget to compile the project and refresh the designer.

Note: Even though explicit creation of Data Provider is not necessary, Table Component implicitly creates the Data Provider. You might want to get information from the underlying Data Provider. For example if you have a column with Button or CheckBox or RadioButton, you might want to find the location of the selected row. Here is a code that would help you to do that.
RowKey[] selectedRowKeys = getTableRowGroup1().getSelectedRowKeys();
MyObject[] myArray = getSessionBean1().getMyArray();
int rowId = Integer.parseInt(selectedRowKeys[0].getRowId());
MyObject myObject = myArray[rowId];
Posted at 10:03PM Oct 14, 2007 | Permanent link to this entry
Thank you for the new enhancements.
I am wondering if the visual table component in NB 6 can bind some javax.faces.model.DataModel ojbects, I can see some no visual JSF/JPA examples doing that way. Meanwhile I would like to know if some list components like dropdown list can bind Array or List objects as the table component does, because those kinds of components are equally useful as table.
Thank you!
Posted by Kane Li on October 15, 2007 at 04:11 AM PDT #
I've tried the array approach, the list approach and the (explicit) DataProvider approach. The list approach won't work, no matter how many times i recompile, refresh the visual editor or restart netbeans. I've tried the following code onn both the session bean and the page's backing bean; any ideas? Thanks! -- Erik
private List<InvoiceDetail> invoiceDetailList;
public List<InvoiceDetail> getInvoiceDetailList() {
return invoiceDetailList;
}
public void setInvoiceDetailList(List<InvoiceDetail> myInvoiceDetailList) {
this.invoiceDetailList = myInvoiceDetailList;
}
Posted by Erik on October 19, 2007 at 07:06 AM PDT #
Hi Erik, which version of NB you are using?. This feature is available only after Netbeans 6.0 Beta1 or later. I tried now, it works for me.
Posted by Winston Prakash on October 19, 2007 at 07:22 AM PDT #
Hi Winston, thanks for your reply. I'm using 6.0beta1.
Posted by Erik on October 19, 2007 at 07:32 AM PDT #
Erik, post your sample code at the nbuser alias (put VWP in the subject), I'll take a look at it.
Posted by Winston Prakash on October 19, 2007 at 07:36 AM PDT #
Winston, my direct list aproach works fine, but I can't find getDataProvider() method in com.sun.webui.jsf.component.Table
Any ideas?
Product Version: NetBeans IDE Dev (Build 20071005123835)
Posted by v.m.kotov on October 23, 2007 at 12:19 PM PDT #
Ha!, my bad. The correct way to get the TableDataProvider is using TableRowGroup Component method tableRowgGroup.getTableRowDataProvider().getTableDataProvider();
Posted by Winston Prakash on October 23, 2007 at 03:00 PM PDT #
Thanks for reply, but getTableRowDataProvider() - has protected access, so I can't call it from for ex. Page1.java.
Posted by v.m.kotov on October 23, 2007 at 03:37 PM PDT #
Hi and thanks for your informative article.
I am having pretty much the same problem with v.m.kotov.
I am using Netbeans 6.0 Beta 1 on a JavaEE5 project. I have created a table with a binding to an ArrayList of POJOs. I now want to add a "delete row" button on each row of the table. I obviously need to access the underlying data provider in order to delete the row, based on the current RowKey. However, I cannot find the getTableRowDataProvider() or getTableDataProvider() methods you are talking about...
Any help would be very much appreciated...
Posted by Zzzzz on October 24, 2007 at 09:35 AM PDT #
OK I found a solution to my problem.
I created a subclass of TableRowGroup and modified the rowGroup of my table so that it is an instance of this subclass. I created a method deleteRow(RowKey rk) in the subclass. The subclass can now access the protected method getTableRowDataProvider(), so I can get a reference to the data provider and delete the row.
Note that I also had to cast the data provider to ObjectListDataProvider, and call commitChanges() in order for the deletion to propagate to the List and the table...
(Hope that this approach also helps v.m.kotov)
All this would be much simpler if getTableRowDataProvider() was public. So is there any good reason that it is declared as protected?
Cheers...
Posted by Zzzzz on October 25, 2007 at 04:45 AM PDT #
Table Component is maintained by Woodstock team only the design time support is maintained by VW team. I talked to Woodstock team. Looks like they did not think there is any need to get back the dataprovider to manipulate the data given to Table Component. He said the possible solution would be use TableRowGroup.getSourceData(). But looks like there may be need for proper casting etc. BTW, it is possible to update, delete, append with out getting back the Dataprovider from table. Look at the article I wrote (which uses Array of Objects obtained from database via JPA) http://www.winstonprakash.com/articles/netbeans/JPA_Add_Update_Delete.html
Posted by Winston Prakash on October 25, 2007 at 07:25 AM PDT #
Thanks Winston, very usefull link, I sugest to replace Note about getTableDataProvider() with smth like this:
RowKey[] selectedRowKeys = getTableRowGroup1().getSelectedRowKeys();
MyObject[] myArray = getSessionBean1().getMyArray();
int rowId = Integer.parseInt(selectedRowKeys[0].getRowId());
MyObject myObject = myArray[rowId];
Posted by v.m.kotov on October 25, 2007 at 02:31 PM PDT #
Thanks. I added your suggestion.
Posted by Winston Prakash on October 25, 2007 at 03:12 PM PDT #
Hi Winston
Thanks for your tip it is very useful for me .
Posted by saeed on October 28, 2007 at 05:59 AM PDT #
Hi Winston.
how can i link a ejb (entity class, in web service) with a Table in visual WEB pack? i want to write acces data model and then use in a VWP project, mobile aplicattion or J2se.
Pd: Sorry for my horrible english. i will study english the next year. it is my promise
Posted by javiersinnada on November 28, 2007 at 03:07 PM PST #
Hi Javier, take a look at my tutorial http://winstonprakash.com/articles/netbeans/JPADataBinding.html. In this one I have separated out the data access as separate model project and view as another web application. You might want something like that, I suppose.
BTW, your English is not that bad :)
Posted by Winston Prakash on November 29, 2007 at 09:25 AM PST #
Hi Winston, i was working on the jpa y vwp tutorial(http://winstonprakash.com/articles/netbeans/JPADataBinding.html), i have a problem, it is when the connection is with postgres...that's the error:
(Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/sample
Error Code: 0
at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:305)
at oracle.toplink.essentials.sessions.DefaultConnector.connect(DefaultConnector.java:102)
at oracle.toplink.essentials.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:184)
.............
note: if drop the dataproviders normally with the same connection it works at perfection.
Posted by Gustavo on December 12, 2007 at 11:38 AM PST #
Hi, thanks for those tutorials, it's realy help me to understood how to manged with db.
I had similar problem to Gustavo with postgresql database, also glassfish displaied that it can't find suitable driver.
Realy 2 days with it, and at last found what's going on, simple you have to add to classpath in glassfish admin console fully-qualified path name for the driver’s JAR file. (Application Server->JVM Setting Tab->Path)
Posted by Jakub on December 27, 2007 at 09:22 AM PST #
Posted by weblog on January 17, 2008 at 01:57 AM PST #
Is it possible to show data from an underlying pojo in the table?
I.e. PojoA has a PojoB property and I want to show a property from PojoB but it's PojoA that's bound to the table. Like this: pojoA.getPojoB.getName().
Posted by Mats on January 30, 2008 at 05:32 AM PST #
You try something like ..
Create a method in the page bean
public String getName(){
PojoB pojoa = (PojoA) getValue("#{currentRow.value['PojoA.PojoB']}");
return pojoa.getName();
}
and then bind this method to the static text in the table column.
Posted by 24.6.110.152 on February 01, 2008 at 01:07 PM PST #
I can't seem to get the table to bind to a list of objects (followed all your instructions). Array of objects works fine as the table in the UI recognizes it as a possible source. When trying to bind to List<MyObject> getMyObjects the table in the UI doesn't see it.
Posted by Mark on February 06, 2008 at 06:41 AM PST #
When binding a Table component to an array/list of POJO, how does the component see properties that are in the subclasses of the POJO? Since the binding is done at design time, the subclass properties don't appear in the "Bind to Data" dialog. That is, if my POJO is Person, which has Employee as a subclass, how do I bind a property of Employee, say worksFor, to the Table component? Any help is greatly appreciated.
Posted by Billy Lim on March 27, 2008 at 07:54 AM PDT #
Hi,
I discovered the following bug while trying to bind some entity classes to a VWP table in Netbeans 6.1 beta:
1. NB does not recognize and show the bean for an Array in Navigator and Dropdown (Table Layout/Get Data From) if the class is not in the same project.
2. NB does not recognize the fields when binding a generic List<E> if class E is not in the same project.
The project containing the entity classes is, of course, added.
Regards,
Markus
Posted by Markus on March 28, 2008 at 06:38 AM PDT #
Markus, a issue has been filed against the problem you mentioned and being investigated.
Posted by 76.102.227.57 on April 01, 2008 at 07:50 AM PDT #
I'm using Netbeans 6.0.1 and NB doesn't recognize my list of beans if the entities are not in the same project. Works well with array of beans though
Posted by 202.90.68.50 on April 02, 2008 at 06:23 PM PDT #
Buen dia Doctor.
tengo una inquietud mas, como se podria hacer una tabla editable con woodstock utilizando una list cuando vinculo la tabla con un ObjectListDataProvider yo lo se hacer pero ahora quisiera probar cuando vinculo la tabla con un simple List,
este es el codigo de la jsp
<webuijsf:table augmentTitle="false" binding="#{Page1.table1}" id="table1"
style="left: 30px; top: 70px; position: absolute; width: 450px" title="Table" width="0">
<webuijsf:tableRowGroup binding="#{Page1.tableRowGroup1}" id="tableRowGroup1" rows="10" sourceData="#{SessionBean1.lista}" sourceVar="currentRow">
<webuijsf:tableColumn binding="#{Page1.tableColumn1}" headerText="codigo" id="tableColumn1" sort="codigo">
<webuijsf:staticText binding="#{Page1.staticText1}" id="staticText1" text="#{currentRow.value['codigo']}"/>
</webuijsf:tableColumn>
<webuijsf:tableColumn binding="#{Page1.tableColumn2}" headerText="nombre" id="tableColumn2" sort="nombre">
<webuijsf:textField binding="#{Page1.textField1}" id="textField1" text="#{currentRow.value['nombre']}"/>
</webuijsf:tableColumn>
</webuijsf:tableRowGroup>
</webuijsf:table>
este es la declaracion de la List en en sessionBean1
List<newPruebaDto> lista=new ArrayList<newPruebaDto>();
public List<newPruebaDto> getLista() {
return lista;
}
public void setLista(List<newPruebaDto> lista) {
this.lista = lista;
}
y la clase newPruebaDto tiene esta declaracion
public class newPruebaDto implements Serializable {
private String codigo;
private String nombre;
public newPruebaDto(String codigo, String nombre) {
this.codigo = codigo;
this.nombre = nombre;
}
public newPruebaDto() {
}
public String getCodigo() {
return codigo;
}
public void setCodigo(String codigo) {
this.codigo = codigo;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
}
agradezco la ayuda porfa
Posted by Jaider rodriguez lozano on April 17, 2008 at 06:19 PM PDT #
Hi Winston,
Thanks a lot for all your tutorials, they have been a great help. I've been having an issue with buttons in a column of a table. When the table is bound to an ObjectListDataProvider the button actions fire appropriately, however if I change the binding to the List, rather than the DataProvider, the button events stop firing.
Any help would be greatly appreciated.
Regards,
Judd
Posted by 59.167.191.34 on April 20, 2008 at 06:06 PM PDT #
No matter if I use an Array or an ObjectListDataProvider, I do not get my table sortable. That is, the sort buttons in the column heads are not provided. What can I do about that?
Thank you for your hints,
Stefan
Posted by Stefan Bley on April 28, 2008 at 04:13 AM PDT #
Hi Winston,
I would like to know if it is possible to use a table component bind to an array object locate on request bean?
I am executing a SQL and saving the result in an array object, however it only work if I locate the array on session bean, but this seems inefficient because all data remain on session even when this is not used
Hola Winston,
Me gustaria saber si es posible usar un table component(incluyendo las funcionalidad de ordenamiento y paginacion) que obtenga los datos de un array ubicado en request?
Actualmente yo estoy ejecutando un SQL y guardando los resultado en un array, para posteriormente cargar los datos en el table component, sin embargo esto solo funciona si localizo el array en Session, ya que si lo localizo en Request seria necesario ejecutar el query cada vez que se pagina o se ordena el listado.
El problema es que ambas cosas me parecen ineficientes, si guardo todos los resultado en sesion estos van a permanecer alli aun cuando no sean usados y si lo guardo en request ejecutaria el Query (select) cada vez que se pagina o se ordena el listado, entonces la pregunta es:
Es posible hacer permanecer los datos cargados en el table component en request sin que sea necesarios recargarlos nuevamente cada vez que se pagine o ordene el listado?
Posted by Roger on April 29, 2008 at 07:14 AM PDT #
Hi Winston,
I am also experiencing the same error as Judd. If I use a List<MyObject> instead of a DataProvider, any buttons in the table columns will not fire.
Is there a solution for this problem?
Thanks.
Josh.
Posted by Josh on May 01, 2008 at 01:29 PM PDT #
Hi, Winston!
I have a POJO with some properties and i can bind it to a table with no problems. I want to diplay one of the properties in that table in text fields, instead of static text, so the user will could change the values. That's ok too. My question is how could I update my pojo list with the values entered by users? If I work with ObjectListDataProvider, I just use commitChanges().
Thanks in advance!
Estevão Lisauskas
Posted by Estevão on May 18, 2008 at 06:32 AM PDT #
All the names of array properties of my java class object are displayed as table-component column titles. However, the contents (values) of these arrays are not displayed on the table. The table says "No items found"
Has anyone else apart from Dr. Winston Prakash succeeded in having the table component display contents of array of pojos?
Posted by Raymond Rugemalira on May 21, 2008 at 10:05 AM PDT #
My problem appears to be similar with the poster above, Raymond Rugemalira.
I am using the array of objects method. After I Bind to Data to a table component (as described in Winston's personal site), but when I run it I am not able to see the data inside the table. In the design view, I can see that the binding is done, but only when I run it, it says on the table "no items found".
It'll be nice if someone can share a solution, as I can do that part two of this tutorial to add, delete & update.
Posted by Marat on July 02, 2008 at 01:16 AM PDT #
The "binding enhancements" for List does work for the woodstock table components, but not for the standard DataTable component. What am i missing? Thanks in advance.
Posted by ts on July 12, 2008 at 01:01 PM PDT #