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

调用SelectOneChoice的valueChangeListener时弹出未保存提示的屏蔽求助

解决ADF中SelectOneChoice触发valueChangeListener时弹出未保存更改提示的问题

问题分析

虽然未启用uncommittedDataWarning属性,但当af:selectOneChoice触发valueChangeListener并执行processUpdates后,组件值的更新会被ADF标记为未提交更改,从而触发不必要的弹窗提示。

解决方案

方法一:在valueChangeListener方法中清除当前组件的未提交状态

在onBookLovChange方法末尾添加代码,同步组件的本地值与模型值,消除未提交标记:

public void onBookLovChange(ValueChangeEvent valueChangeEvent) {                 
    valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
    invokeELMethod("#{bindings.methodToExecute.execute}", new Class[0], new Object[0]);
    AdfFacesContext.getCurrentInstance().addPartialTarget(getBusinessTable());
    
    // 重置当前组件的提交状态
    UIInput inputComponent = (UIInput) valueChangeEvent.getComponent();
    inputComponent.setSubmittedValue(null);
    inputComponent.setValue(inputComponent.getLocalValue());
    inputComponent.setValid(true);
}

方法二:禁用本次请求的未提交数据警告

通过ADF上下文参数,临时禁用当前请求的未保存警告:

public void onBookLovChange(ValueChangeEvent valueChangeEvent) {                 
    valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
    invokeELMethod("#{bindings.methodToExecute.execute}", new Class[0], new Object[0]);
    AdfFacesContext.getCurrentInstance().addPartialTarget(getBusinessTable());
    
    // 禁用本次请求的未提交数据警告
    AdfFacesContext.getCurrentInstance().setProperty("disableUncommittedDataWarning", Boolean.TRUE);
}

方法三:在组件层面直接禁用未提交警告

在af:selectOneChoice组件上添加uncommittedDataWarning="false"属性,覆盖全局配置:

<af:selectOneChoice value="................."
                    label=".................."
                    required="..............."
                    shortDesc=".............." 
                    id="....................."
                    valueChangeListener="#{TransferWorkAreaBean.onBookLovChange}"
                    autoSubmit="true"
                    uncommittedDataWarning="false">
    <f:selectItems value="............" id="si2"/>
    <f:validator binding="......."/>
</af:selectOneChoice>

说明

  • 方法一精准针对当前组件处理,不影响页面其他组件的状态;
  • 方法二通过上下文参数全局控制本次请求的警告逻辑,适合批量处理场景;
  • 方法三直接在组件上配置,操作简单,适合单个组件的需求。

内容的提问来源于stack exchange,提问作者Papai from BEKOAIL

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 18:18:28