You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XPage重复面板绑定子文档数据源异常问题求助

问题与解决

问题概述

开发XPage时,需实现父文档(表单fParent)和关联子文档(表单fChild,通过视图vChildren匹配父文档Key字段)的同时编辑。使用Repeat控件迭代子文档集合,每个子文档通过自定义控件展示编辑,但自定义控件内的document2数据源始终加载父文档数据,而非对应子文档。

错误原因

自定义控件的<xp:view>标签错误添加了binding="#{rowData}"属性,这会将整个视图组件绑定到当前迭代的rowData(子文档对象),干扰了dominoDocument数据源通过documentId加载对应子文档的逻辑,最终导致所有子文档控件都加载父文档数据。

解决方案

  1. 移除自定义控件的视图绑定:删除<xp:view>标签上的binding="#{rowData}"属性,让dominoDocument数据源能正常通过rowData.getNoteID()获取子文档ID。
  2. 优化Repeat数据源:直接使用已定义的view1数据源(已通过categoryFilter过滤出对应父文档的子文档),避免重复调用database.getView,提升性能。

修改后的代码

父文档XPage

<?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.data>
        <xp:dominoDocument formName="fParent" var="document1" />
        <xp:dominoView 
            var="view1" viewName="vChildren"
            categoryFilter="#{document1.Key}">
        </xp:dominoView>
    </xp:this.data>
    
    Name
    <xp:inputText id="inputText2" value="#{document1.Name}"></xp:inputText>
    <xp:br></xp:br>
    
    Key&#160;
    <xp:text escape="true" id="computedField1" value="#{document1['Key']}">
    </xp:text>
    <xp:br></xp:br>
    
    <xp:repeat id="repeat1" rows="30" var="rowData" value="#{view1}">
        <xc:ccChildDoc></xc:ccChildDoc>
    </xp:repeat>
    
    <xp:button id="button1" value="Save" save="true" type="submit"></xp:button>
</xp:view>

子文档自定义控件

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:this.data>
        <xp:dominoDocument 
            formName="fChild" var="document2"
            action="editDocument" computeWithForm="both"
            documentId="#{javascript:rowData.getNoteID();}">
        </xp:dominoDocument>
    </xp:this.data>
    <xp:panel>
        Note id:&#160;
        <xp:text escape="true" id="computedField1" value="#{javascript:document2.getNoteID();}">
        </xp:text>
        <xp:br></xp:br>

        Comment&#160;
        <xp:inputText id="inputText1" value="#{document2.Comment}" readonly="false">
        </xp:inputText>
        <xp:br></xp:br>

        Field2&#160;
        <xp:inputText id="inputText2" value="#{document2.Field2}" readonly="false">
        </xp:inputText>
        <xp:br></xp:br>
        <hr />
    </xp:panel>
</xp:view>

内容的提问来源于stack exchange,提问作者Adam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 14:12:06