Display a Dynamic table with SJSC 2

Hi,

I'm new to SJSC 2 (but not new to Java) and I'm encountering a problem with my small application, here is what I do :

_ create a Web project

_ drag and drop a table component to the design

_ link the table component to a simple table from dataprovider (SQLServer) with only 2 columns : I then remove the columns because I want the table to bedisplayed dynamically.

_ in the Page1 (default main page), in the init() function, here is my code :

try{

ResultSetMetaData res;

res= getSessionBean1().getPersonRowSet().getMetaData();

int nbColumn = res.getColumnCount();

for (int i = 0; i < nbColumn; i++){

TableColumn tableColumn =new TableColumn();

StaticText staticText =new StaticText();

String textValue ="#{currentRow.value['" + res.getTableName(i+1) +"." + res.getColumnName(i+1) +"']}";

staticText.setValue((String) getValue(textValue));

tableColumn.getChildren().add(staticText);

tableRowGroup1.getChildren().add(tableColumn);

}

}catch (SQLException sqle){

log("Error setting columns: " + sqle.toString());

}

The result I get is a table (hopefully...) with all the rows, but these rows are empty and I don't see why... :(

If I retrieve the number of rows, it's ok, it's working, like the column names etc...but I'm not able to display the data...

Can someone please explain me what I'm doing wrong here ?

Thank you.

[1980 byte] By [Olive49] at [2007-11-26 7:28:11]
# 1

The first thing I notice is that you are calling staticText.setValue instead of staticText.setValueBinding. In other words, you must create a ValueBinding from textValue and then call staticText.setValueBinding("text", vb);

One question is whether all the tables that can participate in the query are known prior to runtime. For instance, one common scenario is a reporting application. The user specifies criteria for the query (which will affect the query's WHERE clause) and what information to display (which will affect the query's SELECT clause). In many cases, the tables that will be part of the query do not depend on the user's choices. If this is true in your case, it might be better to have your table component include *all* the possible columns, and then dynamically hide (by setting the column's rendered property to False) the ones the user does not want to see. This is the opposite approach from the one you are currently taking, in which the table component starts out with no columns and you add them dynamically. As long as you can know all the possible columns prior to runtime, I find it simpler to hide columns dynamically than to add them dynamically.

mbohm at 2007-7-6 19:19:07 > top of Java-index,Development Tools,Java Tools...