【问题标题】:Need to know the way to stamp a field within a document collection which is in a repeat control需要知道如何在重复控件中的文档集合中标记字段
【发布时间】:2013-11-04 11:23:24
【问题描述】:

我有一个重复控件,它的来源是 notesdocumentcollection。在重复控件内部,我有一个具有数据源的面板,并且数据源的文档 id 属性设置为单个文档的通用 id,在我的例子中是重复控制变量 apprDoc (apprDoc.getUniversalID)。因此,使用面板数据源,我试图将重复控件中的每个字段直接绑定到相应的后端文档。我有一个单击提交按钮,我需要将用户选择的值发布到后端文档中,并设置一些未绑定到后端文档的其他字段。我需要获取文档集合中每个文档的句柄,以便在后端文档上设置字段值。有人可以建议一种方法来做同样的事情,或者任何其他方式来实现我想要实现的功能。请在下面找到相同的代码:

    <xp:repeat id="repeat1" 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("vwlkAllApprApper");
    var collDocAppr:NotesDocumentCollection = vwlkApprView.getAllDocumentsByKey(sessionScope.EmployeeID);
    if(collDocAppr.getCount() != 0){
        return collDocAppr;
    }
return null;}]]></xp:this.value>
            <xp:panel id="pnlFG">
                <xp:this.data>
                    <xp:dominoDocument formName="frmAppraisal" var="appraisalDoc"
                        action="editDocument" documentId="#{javascript:apprDoc.getUniversalID();}">
                        <xp:this.querySaveDocument><![CDATA[#{javascript:var apprDoc:NotesDocument = appraisalDoc.getDocument();
if(requestScope.SubmitFG == true){
    apprDoc.replaceItemValue("CurrFGRRStatus","1");
    apprDoc.save();
}}]]></xp:this.querySaveDocument>
                    </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");}]]></xp:this.value>
                        </xp:label>
                    </xp:td>
                    <xp:td styleClass="tdCls" style="width:15.0%">
                        <xp:label id="ApeGrade">
                            <xp:this.value><![CDATA[#{javascript:return apprDoc.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);}]]></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);}]]></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);}]]></xp:this.value>
                            </xp:label>
                        </xp:div>
                    </xp:td>
                    <xp:td styleClass="tdCls" style="width:10.0%">
                        <xp:div style="text-align:center">
                            <xp:comboBox id="appeGrades"
                                value="#{appraisalDoc.ApperFinalGrade}" style="width:50.0px"
                                disableClientSideValidation="true">
                                <xp:this.validators>
                                    <xp:validateRequired>
                                        <xp:this.message><![CDATA[#{javascript:var index = parseInt(docIndex)
index = index + 1;
"Please select a final grade in row number " + index.toString();}]]></xp:this.message>
                                    </xp:validateRequired>
                                </xp:this.validators>
                                <xp:selectItem itemLabel="-"
                                    itemValue="">
                                </xp:selectItem>
                                <xp:selectItem itemLabel="1"
                                    itemValue="1">
                                </xp:selectItem>
                                <xp:selectItem itemLabel="2"
                                    itemValue="2">
                                </xp:selectItem>
                                <xp:selectItem itemLabel="3"
                                    itemValue="3">
                                </xp:selectItem>
                                <xp:selectItem itemLabel="4"
                                    itemValue="4">
                                </xp:selectItem>
                                <xp:selectItem itemLabel="5"
                                    itemValue="5">
                                </xp:selectItem>
                            </xp:comboBox>
                        </xp:div>
                    </xp:td>
                </xp:tr>
            </xp:panel>
        </xp:repeat>

【问题讨论】:

    标签: controls xpages repeat


    【解决方案1】:

    带有简单操作“保存数据源”的按钮呢?这应该保存 XPage 上可用的所有数据源。

    【讨论】:

    • 是的,我可以使用您提到的相同方法保存所有文档。挑战在于这只会保存具有值绑定的字段。除了具有值绑定的字段外,我还需要将一些字段直接设置到集合中的后端文档中,这是在我的工作流程中维护这些文档的状态所必需的。
    • 只是补充一下,我尝试在面板中定义的数据源的 querydocumentsave() 事件上设置字段,它确实为字段设置了值,但在这种情况下,它最终导致了保存冲突而且它也没有设置定义了值绑定的字段。
    • 我明白了...尝试将脚本操作添加到在“保存数据源”之后运行的“保存数据源”按钮。在脚本操作中,使用 documentCollection.stampAll()。这是一个很好的机会,这将起作用并且不会产生保存冲突。另一种想法是使用 postSave 事件并执行 document.getDocument().save(),但这会更慢。
    • 非常感谢我尝试了您建议的第二种方法(将其保存在 postSave() 中)并且它可以正常工作而不会产生冲突。如果我想使用您建议的第一种方法,我将如何在按钮单击时获取对 documentCollection 对象的引用,因为集合位于重复控件内。如果这似乎是一个愚蠢的问题,我很抱歉,但我只是 x-Pages 的初学者。
    • 试着改掉使用replaceItemValue的习惯...appraisalDoc.setValue("CurrFGRRStatus","1")会产生想要的结果而没有replaceItemValue的副作用。
    【解决方案2】:

    重复元素的计算效率不高 - JSF 生命周期会让您查找两次值。你可以试试这个:

    // If we looked them up before we don't need to do anything
    if (viewScope.approveIDs) {
       return viewScope.approveIDs;
    }
    // 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("vwlkAllApprApper");
    var collDocAppr:NotesViewEntryCollection = vwlkApprView.getAllEntriesByKey(sessionScope.EmployeeID);
    // Don't do a count, slow!
    var result = new java.util.Vector();
    // Add all unids
    var ve:NotesViewEntry = collDocAppr.getFirstEntry();
    while (ve != null) {
        var nextVe = ve.getNextEntry(ve);
        result.add(ve.getUniversalId()); // eventually check to avoid categories?
        ve.recyle();
        ve = nextVe;
    }
    viewScope.approveIDs = result.isEmpty() ? null : result;
    collDocAppr.recyle();
    vwlkApprView.recycle();
    return viewScope.approveIDs;
    

    这段代码(我不记得了,所以请检查语法)有一些值得注意的属性:

    • 缺少错误处理,请多加try { } catch(e ) { }
    • .recyle() 用于释放内存
    • ViewEntryCollection 代替 DocumentCollection -> 更好的性能
    • UNID 缓存在 Vector 中,因此只需要运行一次
    • 变量 apprDoc 现在直接包含 unid,在面板中保存文档调用
    • 变量 docIndex 也可以与 viewScope.approveIds.get() 一起使用以获取对 ID 的访问权限
    • 如果您将所有字段都放入视图中,您可以轻松扩展示例而不是向量中的 Stings,使用自定义对象 (bean) 并摆脱数据源(最终可能有助于提高性能),因此您可以继续使用viewNavigator

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-30
      • 1970-01-01
      • 2021-11-04
      • 2017-11-27
      • 1970-01-01
      相关资源
      最近更新 更多