How to get table fields programatically?
I am using a table component with associated data provider. In the same form, I need to have a drop down with the values same as the columns/fields of the table. I am looking at the APIs to find a way to access the table fields/columns, so that I can have them in the drop down, but I can't find out.
Please note that I need to access the field names (i.e First_Name, Last_Name, User_Name, etc.) not the field values (i.e Joe, Bloe, jbloe, etc.) If it was field values, there are tons of example out there. Actually, I am trying to build searhing, where users can pick a field from the drop down, and type text to search on that field. See the screenshots here:
http://bedriven.blogspot.com/2006/08/filtering-data-table-in-java-studio.html
[759 byte] By [
Sabir] at [2007-11-26 9:40:57]

# 1
I made some progress and now I am able to get the table column header text and loop through it, and put its value in the drop down. I still can't get the column header field name (field name is different than the header name -- i.e field name is "last_name", where as header text is "Last Name").
Here is my code:
Iterator it=getTableRowGroup1().getTableColumnChildren();
Option options[]=new Option[getTableRowGroup1().getColumnCount()];
info("Count="+getTableRowGroup1().getColumnCount());
int i=0;
while (it.hasNext()){
TableColumn column=(TableColumn)it.next();
info("1:"+column.getHeaderText());
options[i]=new Option(column.getHeaderText(), column.getHeaderText());
i++;
}
Sabir at 2007-7-7 0:38:56 >

# 3
I tried this:
tableRowGroup.getSourceData().getFieldKeys()
but, the problem is, it gives me the field names, but not the display values. I want to use the display values (i.e Last Name) for dropdown text, and field keys (i.e user_last_name) for dropdown values.
I ended up using this code to get the list of column fileds (field name in database) and the column header (display value in table header):
Iterator it=getTableRowGroup1().getTableColumnChildren();
Option options[]=new Option[getTableRowGroup1().getColumnCount()];
int i=0;
while (it.hasNext()){
TableColumn column=(TableColumn)it.next();
if (column.getSort()!=null){
options[i]=new Option(column.getSort().toString(), column.getHeaderText());
}else{
options[i]=new Option(column.getHeaderText(), column.getHeaderText());
}
i++;
}
This approach works fine. The only problem is that getTableColumnChildren returns size 0 when the page is loaded the first time. It works fine on the subsequent post backs. You can see this reported by other users as well:
http://swforum.sun.com/jive/thread.jspa?threadID=101630&tstart=0
Sabir at 2007-7-7 0:38:57 >
