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

视图对象无指定Key行时创建行失败,页面加载异常求排查

解决ADF单行View Object无数据时无法创建行的问题

看起来你遇到的核心问题是:当单行VO查询不到指定Key的行时,页面因无数据加载异常,且createRow未被触发。结合你的配置,我帮你梳理下遗漏的关键配置点和调整方向:


1. 错误的RefreshCondition判断逻辑

你当前使用的RefreshCondition="#{bindings.MyVO1Iterator.queryModel == null}"并不准确——queryModel不为null仅表示存在查询模型,而非查询结果为空。正确的判断应该是检查查询后返回的行数是否为0,比如:

#{bindings.MyVO1Iterator.estimatedRowCount == 0}

2. 缺少触发createRow的Action配置

你现有的invokeAction只执行了Rollback和查询操作,根本没有调用createRow的逻辑!需要先在pageDef中添加创建行的Action:

<action id="CreateMyVORow" 
        IterBinding="MyVO1Iterator" 
        InstanceName="MyAppModuleDataControl.MyVO1" 
        DataControl="MyAppModuleDataControl" 
        RequiresUpdateModel="true" 
        Action="createRow"/>

然后通过invokeAction在查询无结果时触发这个Action,注意执行顺序必须在查询之后:

<!-- 先执行带参数的查询 -->
<invokeAction Binds="EventTypesExecuteWithParams" id="invokeEventTypes" Refresh="ifNeeded"/>
<!-- 查询无结果时创建行 -->
<invokeAction id="CreateEmptyRow" 
              Binds="CreateMyVORow" 
              Refresh="always" 
              RefreshCondition="#{bindings.MyVO1Iterator.estimatedRowCount == 0}"/>

3. 确保Iterator的RangeSize配置正确

因为是单行VO,要保证你的MyVO1Iterator的RangeSize属性设置为1(默认可能是-1,表示所有行),这样查询后只会返回一行,也符合单行视图的需求。

4. 页面绑定的容错处理

如果页面组件直接绑定到VO行的属性,当无数据时会抛出空指针异常。可以在页面EL中添加判断,比如:

<af:inputText value="#{bindings.MyAttribute.inputValue}" 
              rendered="#{bindings.MyVO1Iterator.estimatedRowCount > 0}"/>

或者用af:iterator包裹组件,确保只有存在行时才渲染绑定内容。


完整的pageDef配置示例

整合以上调整后,相关配置大概是这样:

<action IterBinding="MyVO1Iterator" id="EventTypesExecuteWithParams" 
        InstanceName="MyAppModuleDataControl.AccidentIVVVO" 
        DataControl="MyAppModuleDataControl" 
        RequiresUpdateModel="true" Action="executeWithParams">
</action>

<action id="CreateMyVORow" 
        IterBinding="MyVO1Iterator" 
        InstanceName="MyAppModuleDataControl.MyVO1" 
        DataControl="MyAppModuleDataControl" 
        RequiresUpdateModel="true" 
        Action="createRow"/>

<invokeAction Binds="EventTypesExecuteWithParams" id="invokeEventTypes" Refresh="ifNeeded"/>
<invokeAction id="CreateEmptyRow" 
              Binds="CreateMyVORow" 
              Refresh="always" 
              RefreshCondition="#{bindings.MyVO1Iterator.estimatedRowCount == 0}"/>

这样配置后,当查询无结果时会自动创建一行空数据,页面就能正常加载并允许用户编辑了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 07:01:35