سؤال

This code does provide me the values I am wanting in my comboBox, but I am wondering if there is a way to get the viewColumn ID, viewColumnHeader ID, and number of columns in the viewPanel programmatically. The viewPanel is using a JDBCQuery as the datasource.

var itemList:java.util.Vector = new java.util.Vector;
var colID = "viewColumn"; //default id assigned
var colHeaderID = "viewColumnHeader"; //default id assigned
var end = 10; //max # of viewPanel columns
itemList.add("Select Column");
for(x=1;x<end;x++) {
    try {
        if(getComponent(colID + x) == null) {
            throw ("Only " + (x-1) + " columns in ViewPanel");
        x=end;
        } else {
        var disColID = getComponent(colID + x).getColumnName();
        }
        var disColHeaderID = getComponent(colHeaderID + x).getValue();
        itemList.add(disColHeaderID + "|" + disColID);
    } catch (e) {
        dBar.info(e.toString());
    }
}

itemList

The current way is obviously restricted to only 9 columns and ensuring the viewColumn ID and viewColumnHeader ID have a specific naming structure which would be nice to get away from.

هل كانت مفيدة؟

المحلول

All the columns of a view panel can be accessed by getting the child components of view panel using viewPanelObj.getChildren(). The column headers are a part of view column and after you get the handle of view column you can access the header using viewColumnObj.getHeader().

So a sample SSJS code to access all the view columns and view headers would look something like this:

var viewPnl:com.ibm.xsp.component.xp.XspViewPanel = getComponent("viewPanel1");
var list:java.util.List = viewPnl.getChildren();
for (var i=0 ; i<list.size() ; i++) {
    var viewCol:com.ibm.xsp.component.xp.XspViewColumn = list.get(i);
    var viewHdr:com.ibm.xsp.component.xp.XspViewColumnHeader = viewCol.getHeader();

    // Perform required operations on objects of viewCol & viewHdr
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top