Access to data for JDBC query in ViewPanel on XPage via OpenNTF driver

316 Views Asked by At

We have an XPage which is using a named JDBC connection via the OpenNTF extension library.

This is successfully retrieving data and placing it inside a View Panel, I've selected to display a Check Box next to first field in the Row, and need to access the returned value for that field in that row (or an array for multiples of the selected rows).

So far have tried these methods:

var Docs2=getComponent("viewPanelDocs");
//var db2 = Docs2.getAttributes();
//var doc2Array=Docs2.getSelectedIds();
//var test = getComponent("something");
var p=Docs2.getParent()
var pp=something.getColumnValue("extName")
var Rows = Docs2.getChildCount().valueOf();
var doc2Array= new Array();
var SelectedDocs2 = new Array();
for(i=0; i < Rows; i++) {
        // Works, no output: var Selected2Docs=Docs2.getAttributes();
        // FAILS: var Selected2Docs=Docs2_xspGetRendererData();
        // WORKS, no output: var Selected2Docs=Docs2._xspGetRendererData();
        // WORKS, gets local ID of viewPanel: var Selected2Docs=Docs2.getId();
        // Works: javax.faces.component.UIComponentBase$AttributesMap@0: var Selected2Docs=Docs2.getAttributes();
        // FAILS, doesn't like string: var Selected2Docs=Docs2.getAttributes("ExternalUNCLink");
        // WOrks, no output: var Selected2Docs=Docs2.getAttributes().get("ExternalUNCLink");
        // Fails, something, something: var Selected2Docs=Docs2.getAttributes().values("ExternalUNCLink");
        var Selected2Docs=Docs2.toString().valueOf();
        doc2Array.push(Selected2Docs);
}
getComponent("Docs2").value=Rows + ": " + @Implode(doc2Array, ",");
//viewScope.put("Documents", @Implode(docArray, ","));

Any clues how to access the returned value of ExternalUNCLink?

Caveat: I'm not a Domino developer, so excuse me if some of the terminology is incorrect.

[EDIT]

We have a JDBC driver, which lives in the Packages -> Web Content -> WEB-INF -> jdbc folder with a test name and four criterea in an XML style format, thus:

<jdbc>
    <driver>net.sourceforge.jtds.jdbc.Driver</driver>
    <url>jdbc:jtds:sqlserver://malbec/aps_dsql</url>
    <user>user</user>
    <password>pass</password>
</jdbc>

Then on the page we have an SQL query in the afterPageLoad event:

var TmpSql="select * from TABLE"
viewScope.put("SQLQuery", TmpSql );
getComponent("strSQLQuery").value=TmpSql;

After that, you put the viewScope variable "SQLQuery" into the value field for sqlQuery on a JDBCQuery view, using the connectionName variable of the name of the JDBC driver shown above. It returns the data, but we can't seem to access it.

[/EDIT]

[EDIT2]

(with apologies for the dogs breakfast ...)

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xc="http://www.ibm.com/xsp/custom">

    <xp:this.afterPageLoad><![CDATA[#{javascript:var TmpSql="select A.extName,A.extUNC,A.extObjInstID,LEFT(A.extUNC,5) as Category, B.cltMailName From cdblink A inner join cdbClientMaster B on A.extobjinstid=B.objInstID where extobjectid=1 and extobjinstid in (1536,1871,632)"
viewScope.put("strSQLQuery", TmpSql);
getComponent("strSQLQuery").value=TmpSql;
getComponent('viewPanelDocs').getData().refresh();
}]]></xp:this.afterPageLoad>
    <xc:testjdbcrowdataaccess></xc:testjdbcrowdataaccess>
    <xp:br></xp:br>
    <xp:br></xp:br>
    <xp:button value="Label" id="button1">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="complete">
            <xp:this.action><![CDATA[#{javascript:
// --var vp=getComponent("viewPanelDocs");
// --
// --//var test=vp._xspGetRendererData().getParent();
// --//var test=vp._xspGetStateId().valueOf();
// --//var test= vp.getChildren().lastIndexOf();
// --var test= vp.getChildren().size();
// --var test=vp.getChildCount();
// --var test=vp._xspGetStateId().valueOf();
// --//var test=vp._xspGetReadOnlyObj().hashCode();
// --//var test=vp.getAttributes().get();
// --var test=vp.getFamily().valueOf();
// --var test=vp.getParent();
// --
// --getComponent("Test").value=test.toString();

//var database=mssql_test.jdbc;
//
//var viewPanel=getComponent("viewPanelDocs");// get the componet of viewPanel
//var docIDArray=viewPanel.getSelectedIds(); //get the array of document ids
//for(i=0; i < docIDArray.length; i++){
 //   var docId=docIDArray[i];
  //  var doc=database.getDocumentByID(docId); 
    // .. your code to deal with the selected document

//    getComponent("Test").value=doc.toString();
//}

var test = getComponent("viewPanelDocs").value;
@ErrorMessage("ID: "+test);}]]></xp:this.action>
        </xp:eventHandler></xp:button>
    <xp:br></xp:br>
    <xp:br></xp:br>
    <xp:br></xp:br><xp:table id="DEBUG" style="width:100%">
        <xp:tr>
            <xp:td>inputText2</xp:td>
            <xp:td>
                <xp:inputText id="inputText2" value="#{viewScope.searchDOCID}" style="width:100%">
                    <xp:eventHandler event="onfocus" submit="true" refreshMode="complete" id="eventHandler2">
                        <xp:this.action>
                            <![CDATA[#{javascript:
                                var viewPanel:com.ibm.xsp.component.xp.XspViewPanel = getComponent('viewPanel2');
                                var dominoView:com.ibm.xsp.model.domino.DominoViewData = viewPanel.getData();
                                var filterValue = getComponent('inputText2').getValue();
                                if (filterValue == 'NA') {
                                filterValue = '';}
                                viewScope.clear()
                                dominoView.setKeys(filterValue);}]]>
                        </xp:this.action>
                    </xp:eventHandler>
                </xp:inputText>
            </xp:td>
        </xp:tr>
        <xp:tr>
            <xp:td>inputText3 (displayvar)</xp:td>
            <xp:td>
                <xp:inputText id="inputText3" value="#{viewScope.documentDOCID}" style="width:100%">
                </xp:inputText>
            </xp:td>
        </xp:tr>
        <xp:tr>
            <xp:td>Test</xp:td>
            <xp:td>
                <xp:inputText id="Test" style="width:100%" value="#{viewScope.test}">
                </xp:inputText>
            </xp:td>
        </xp:tr>
        <xp:tr>
            <xp:td>inputText1</xp:td>
            <xp:td>
                <xp:inputText id="inputText1" style="width:100%"></xp:inputText>
            </xp:td>
        </xp:tr>
        <xp:tr>
            <xp:td>inputText4</xp:td>
            <xp:td>
                <xp:inputText id="inputText4" style="width:100%"></xp:inputText>
            </xp:td>
        </xp:tr>
        <xp:tr>
            <xp:td>SQLQuery</xp:td>
            <xp:td>
                <xp:inputText id="strSQLQuery" style="width:100%" defaultValue="strSQLQuery">
                </xp:inputText>
            </xp:td>
        </xp:tr>
        <xp:tr>
            <xp:td>SQLQueryCat</xp:td>
            <xp:td>
                <xp:inputText id="strSQLQueryCat" style="width:100%">
                </xp:inputText></xp:td>
        </xp:tr>
        <xp:tr>
            <xp:td>Doc1</xp:td>
            <xp:td>
                <xp:inputText id="Docs" style="width:100%">
</xp:inputText>
            </xp:td>
        </xp:tr>
        <xp:tr>
            <xp:td style="width:15%">Doc2</xp:td>
            <xp:td>
                <xp:inputText id="Docs2" style="width:100%"></xp:inputText>
            </xp:td>
        </xp:tr>
        <xp:tr>
            <xp:td>scopeVariable.Documents</xp:td>
            <xp:td>
                <xp:inputText id="svDocuments" style="width:100%"></xp:inputText>
            </xp:td>
        </xp:tr>
        <xp:tr>
            <xp:td>scopeVariable.Recipients</xp:td>
            <xp:td>
                <xp:inputText id="svRecipients" style="width:100%"></xp:inputText>
            </xp:td>
        </xp:tr>
    </xp:table></xp:view>

[/EDIT2]

2

There are 2 best solutions below

0
On BEST ANSWER

It looks like the answer to my question is a three part one - firstly we use the Domino side of things to get the boxes which are checked, thus:

var Docs2=getComponent("viewPanelDocs");
var APKArray=Docs2.getSelectedIds();
//getComponent("svDocuments").value=@Implode(APKArray,",");

Then we use the OpenNTF "Model" Java code to get an array of the documents inside the SQL selection:

// get the Array from the SQL selection
var namesArray=[];
var PathArray=[];
var locationArray = [];
var FinalNames=[];
var FinalLocations=[];

var Model:com.ibm.xsp.component.xp.XspViewColumn = getComponent("xxxviewColumn3");
var modelData=Model.getDataModel();
var Rows = Model.getChildCount().valueOf();
namesArray.push(Rows);
for(i=0; i < modelData.getRowCount(); i++) {
    modelData.setRowIndex(i);
    var x=modelData.getRowIndex();
    var y=modelData.getRowData().getColumnValue("ExternalName").toString();
    var z=modelData.getRowData().getColumnValue("ExternalUNCLink").toString();
    namesArray.push(x);
    locationArray.push(y);
    PathArray.push(z);
}                       
//getComponent("Docs2").value=namesArray

Then we use the index from the Domino side, to reference the names on the SQL side, and put that into a new array:

// put the selected docs in the selected array

for(i=0; i < APKArray.length; i++) {
    var z = APKArray[i].valueOf();
    FinalNames.push(PathArray[z].valueOf() + "\\" + locationArray[z].valueOf())
    //FinalLocations.push(locationArray[z].valueOf())
}

getComponent("Docs2").value=@Implode(FinalNames,",");

The Path + Names ends up in the Docs2 edit box. It's pretty messy, but works (I hope this doesn't ruin my caveat!!)

5
On

When you have a ViewPanel that is linked to a Notes View, the selected documents can be found using the getSelectedIds() method on the viewPanel object. You then can loop through the values to get the documents and their full URLs:

var viewPanel=getComponent("viewPanel1");get the componet of viewPanel
var docIDArray=viewPanel.getSelectedIds(); get the array of document ids
for(i=0; i < docIDArray.length; i++){
    var docId=docIDArray[i];
    var doc=database.getDocumentByID(docId); 
    // .. your code to deal with the selected document
}

Might work for your JDBC use case too.