Melvin Koh's Weblog
I'm just a contractor
Wednesday August 02, 2006
Manual display of table contents in Java Studio Creator 2
I'm playing around with the new Java Studio Creator 2 recently and find that it is able to perform alot of powerful stuff very easily. For example, to display the content of a database table, just create a JSF table component, from the datasources drag the database table to the table component and you're done! The JSF table component should now list the content of the database table with the columns representing each fields. To customize the table, just click on the column and modify the properties or edit the JSP codes if you're programming inclined.

All these is well and good but what happen if the content is not stored in a proper database? I wanted to display the content of a textfile in the JSF table and it took me a while to figure how to do that. The trick is to use either a Object List or Object Array Data provider. Firstmost, I drag-n-drop an ObjectListDataProvider to my page. Then I need to create a javabean wrapper class for my data in the textfile. In the page init(), I do whatever I need to read the first line of datafile, transfer to the bean object, throw it into an ArrayList, and repeat for each line until EOF. Next assign the ArrayList to the ObjectListDataProvider by doing:
objectListDataProvider.setList(arrayList);
Finally I need to bind this data provider to the JSF table. I switched to the JSP view, locate the table code and change the sourceData="#{....}" to:
<ui:tableRowGroup binding="#{main.tableRowGroup1}"
id="tableRowGroup1" rows="10"
sourceData="#{page1.objectListTableDataProvider}"
sourceVar="currentRow">
For each column, I also have to change the text="#{currentRow.value['xxx']}" by replace xxx with the variable name of the javabean class, then I'm done!
Posted by melvin
( Aug 02 2006, 03:45:58 PM SGT )
Permalink
This is a personal weblog, I do not speak for my employer.