0
votes

I am working on this functionality where-in I need to provide the user with a list of documents and provide an option for the user to change/add values to a field(s) inside these documents. I was going through this example Xpages - Display filtered Document Collection in a repeat control and did a similar implementation and got it to work. So what I have now is a panel inside a repeat which has its data source set with the form and document id set to return the value in the repeat control variable (which is the document UNID from the document collection), thus I am able to bind fields directly to these documents using the data source defined in the panel. The challenge is that I want to get the handle to these documents to set a particular value in them and also save the values in the fields that I bind to the back-end document. Is there any way I can access the documents from outside the repeat control (let say on the click of a button)? Following is my code for the repeat:

    <xp:repeat id="rptApprDocuments" rows="30" var="apprDoc"
            indexVar="docIndex" first="0">
            <xp:this.value><![CDATA[#{javascript:// Look up the employee details view to get the employee appraisal details from the current database
    var curDB:NotesDatabase = session.getCurrentDatabase();
    var vwlkApprView:NotesView = curDB.getView("vwlkApprAllFGCompAppr");
    var collDocAppr:NotesDocumentCollection = vwlkApprView.getAllDocumentsByKey(sessionScope.key);
    var apprDocCount = collDocAppr.getCount();
    if(apprDocCount != 0){
        var docAppr:NotesDocument;
        var docUNIDArray = new Array();
        for(i=0;i<apprDocCount;i++){
            docAppr = collDocAppr.getNthDocument(i+1);
            //print(docAppr.getUniversalID());
            docUNIDArray.push(docAppr.getUniversalID());                        
        }
        viewScope.put("docUNIDArray",docUNIDArray);
        return docUNIDArray;
        /*return collDocAppr;
        /return sortColByItemName(collDocAppr, "AppraiseeCWLCluster");*/        
    }
return null;

]]></xp:this.value>
            <xp:panel id="pnlRR">
                <xp:this.data>
                    <xp:dominoDocument formName="frmAppraisal" var="appraisalDoc"
                        action="editDocument" ignoreRequestParams="true">
                        <xp:this.postSaveDocument><![CDATA[#{javascript:if(requestScope.SubmitRR == true){
    appraisalDoc.setValue("ApperRRStatus","1");
    appraisalDoc.save();
}}]]></xp:this.postSaveDocument>
                        <xp:this.documentId><![CDATA[#{javascript://apprDoc.getUniversalID();
return apprDoc;}]]></xp:this.documentId>
                    </xp:dominoDocument>
                </xp:this.data>
                <xp:tr>
                    <xp:td styleClass="tdCls" style="width:2%">
                        <xp:label id="SrNo">
                            <xp:this.value><![CDATA[#{javascript:var index = parseInt(docIndex)
index = index + 1;
index.toString();}]]></xp:this.value>
                        </xp:label>
                    </xp:td>
                    <xp:td styleClass="tdCls" style="width:20.0%">
                        <xp:label id="ApeName">
                            <xp:this.value><![CDATA[#{javascript://return apprDoc.getItemValueString("AppraiseeName");
return appraisalDoc.getItemValueString("AppraiseeName");}]]></xp:this.value>
                        </xp:label>
                    </xp:td>
                    <xp:td styleClass="tdCls" style="width:8.0%">
                        <xp:label id="ApeGrade">
                            <xp:this.value><![CDATA[#{javascript://return apprDoc.getItemValueString("Appraisee_Grade");
return appraisalDoc.getItemValueString("Appraisee_Grade");}]]></xp:this.value>
                        </xp:label>
                    </xp:td>
                    <xp:td styleClass="tdCls" style="width:15.0%">
                        <xp:div style="text-align:center">
                            <xp:label id="appeTotImpRate"
                                style="font-size:10pt;color:rgb(255,0,0);font-weight:bold">
                                <xp:this.value><![CDATA[#{javascript://return apprDoc.getItemValueDouble("AppeTotImpRate").toFixed(2);
return appraisalDoc.getItemValueDouble("AppeTotImpRate").toFixed(2);}]]></xp:this.value>
                            </xp:label>
                        </xp:div>
                    </xp:td>
                    <xp:td styleClass="tdCls" style="width:15.0%">
                        <xp:div style="text-align:center">
                            <xp:label id="apprTotImpRate"
                                style="color:rgb(255,0,0);font-size:10pt;font-weight:bold">
                                <xp:this.value><![CDATA[#{javascript://return apprDoc.getItemValueDouble("ApprTotImpRate").toFixed(2);
return appraisalDoc.getItemValueDouble("ApprTotImpRate").toFixed(2);}]]></xp:this.value>
                            </xp:label>
                        </xp:div>
                    </xp:td>
                    <xp:td styleClass="tdCls" style="width:15.0%">
                        <xp:div style="text-align:center">
                            <xp:label id="revTotImpRate"
                                style="font-size:10pt;color:rgb(255,0,0);font-weight:bold">
                                <xp:this.value><![CDATA[#{javascript://return apprDoc.getItemValueDouble("RevTotImpRate").toFixed(2);
return appraisalDoc.getItemValueDouble("RevTotImpRate").toFixed(2);}]]></xp:this.value>
                            </xp:label>
                        </xp:div>
                    </xp:td>
                    <xp:td styleClass="tdCls" style="width:12.0%">
                        <xp:div
                            style="font-size:10pt;color:rgb(255,0,0);font-weight:bold;text-align:center">
                            <xp:comboBox id="apprGrades" style="width:50.0px"
                                disableClientSideValidation="true" value="#{appraisalDoc.ApperFinalGrade}"
                                readonly="true">
                                <xp:selectItem itemLabel="-" itemValue=""
                                    id="selectItem1">
                                </xp:selectItem>
                                <xp:selectItem itemLabel="1" itemValue="1"
                                    id="selectItem2">
                                </xp:selectItem>
                                <xp:selectItem itemLabel="2" itemValue="2"
                                    id="selectItem3">
                                </xp:selectItem>
                                <xp:selectItem itemLabel="3" itemValue="3"
                                    id="selectItem4">
                                </xp:selectItem>
                                <xp:selectItem itemLabel="4" itemValue="4"
                                    id="selectItem5">
                                </xp:selectItem>
                                <xp:selectItem itemLabel="5" itemValue="5"
                                    id="selectItem6">
                                </xp:selectItem>
                            </xp:comboBox>
                        </xp:div>
                    </xp:td>
                    <xp:td styleClass="tdCls" style="width:12.0%">
                        <xp:div
                            style="font-size:10pt;color:rgb(255,0,0);font-weight:bold;text-align:center">
                            <xp:comboBox id="ApperRelativeRank" style="width:50.0px"
                                disableClientSideValidation="true" value="#{appraisalDoc.ApperRelativeRank}">
                                <xp:this.readonly><![CDATA[#{javascript:/*if(compositeData.UserRole == "Appraiser"){
    return true;
}
if(parseInt(appraisalDoc.getValue("CurrFGRRStatus")) >= parseInt(compositeData.compStatus)){
    return true;
}*/
return false;}]]></xp:this.readonly>
                                <xp:this.rendered><![CDATA[#{javascript:/*if(compositeData.UserRole == "Appraiser"){
    return false;
}*/
return true;}]]></xp:this.rendered>
                                <xp:selectItem itemLabel="-" itemValue=""
                                    id="selectItem13">
                                </xp:selectItem>
                                <xp:selectItems>
                                    <xp:this.value><![CDATA[#{javascript:// Look up the employee details view to get the employee appraisal details from the current database
    var curDB:NotesDatabase = session.getCurrentDatabase();
    var vwlkApprView:NotesView = curDB.getView("vwlkCWLApprAllFGCompAppr");
    var cwlCluster = appraisalDoc.getItemValueString("AppraiseeCWLCluster");
    var collEntAppr:NotesViewEntryCollection = vwlkApprView.getAllEntriesByKey(sessionScope.key + cwlCluster);
    var entCount = collEntAppr.getCount() 
    if(entCount != 0){
        var ranks = new Array();
        var rankValue, rankLabel;
        for(i=0;i<entCount;i++){
            rankValue = i + 1;
            rankLabel = rankValue + "/" + entCount;
            ranks.push(rankLabel + "|" + rankValue);
        }
        return ranks;
    }
return null;}]]></xp:this.value>
                                </xp:selectItems>
                            </xp:comboBox>
                        </xp:div>
                    </xp:td>
                </xp:tr>
            </xp:panel>
        </xp:repeat>
1
What I don't get at the moment is why you wish to access document data from OUTSIDE the repeat. Any reason speaking against inline editing? - Apart from that your code sample appears way too complicated: I don't see why you build a doc collection from a view, then iterate through the collection to build an array which then you feed to the repeat. Why not directly use a view datasource? But maybe I don't get the use case.Lothar Mueller
Hi Lothar thanks for your response. I agree there might be a better way to achieve this but I am relatively new to xPages. I'll try to explain what I want and may be you can suggest a better solution: I am having a list of documents in my database which I need to filter and display based on the role of the user who has logged in. For e.g. If the appraiser logs in he should be able to see only appraisees listed below him in the hierarchy. Not only this but he should be able to sort the employees by name, grade and designation and rate them using a combo-box list values (1 to 5).Nash

1 Answers

0
votes

You can access the data sources of a panel, see http://xpageswiki.com/web/youatnotes/wiki-xpages.nsf/dx/Work_with_datasources#Reset+%2F+clear+a+datasource for example code.

But that solves only half of the problem, you need a handle to each panel inside the repeater. You can find an XPages API browser on openNTF (I don't know the exact name at the moment). Taking this, you can examine the repeat's control at runtime and check for methods and properties. I bet there is something to get components that are inside the repeater.