从托管 bean 中的 ADF SelectOneChoice 获取所选项目

Getting selected item from an ADF SelectOneChoice in managed bean

我目前正在使用 Jdev v12.2.1.4.0 (Oracle 12c) 改造 ADF Fusion Web 应用程序。

在其中一个 jsf 页面上,我在 table 列中有一个 SelectOneChoice。 jsf 实现如下所示:

    <af:column 
        headerText="#{ManagedBean.column5HeaderText}"
        sortable="false"  
        visible="true" 
        id="c5">
        <af:selectOneChoice 
            binding="#{ManagedBean.bindingErrorCaseSelectOneChoice}"
            label="error case" 
            unselectedLabel="---" 
            autoSubmit="true"
            id="soc1">
            <f:selectItems value="#{ManagedBean.errorCases}" id="si1"/>
        </af:selectOneChoice>
    </af:column>

我省略了 required 属性,因为进程没有必要在此处 select 一个值。 我的ManagedBean.java相关部分如下:

    //declaring
    private RichSelectOneChoice bindingErrorCasesSelectOneChoice;
    private  List<SelectItem> errorCases = new ArrayList<SelectItem>();

    //...

    //populating errorCases List from a database
    public void getErrorCasesFromDB() {
    errorCases= new ArrayList<SelectItem>();
    
    try {
        //HC is a helper class to connect to a specific database
        Conection conn = HC.getConn();
        PreparedStatement pstmt = conn.prepareStatement("some SQL");
        ResultSet rs = pstmt.executeQuery();
        
        while (rs.next()) {
            errorCases.add(new SelectItem("i"+ rs.getRow(), rs.getString(1)));
        }
        conn.close();
    } catch(Exception e) {
        e.printStackTrace();
    }
}

当我 运行 jsf 页面时,table 中的 SelectOneChoices 得到呈现,并且所有预期的项目都被征募。每当我尝试访问 SelectOneChoice 的 selected 项时,我都会遇到问题。

我想在点击页面上的按钮时读取 selectedItem 的值,所以我想我可以不必在 valueChangeListener 中处理它,并在我的按钮动作:

    public void buttonSaveReceivedResults(ActionEvent actionEvent) {
        //...
        if (bindingErrorCaseSelectOneChoice.getValue != null) {
            //... insert the selected value into an SQL statement
            //in the case the unselected label is selected, skip
            System.out.println(bindingErrorCasesSelectOneChoice.getValue().toString())
        }
    }

这个块总是被跳过。此外,当我检查该过程时,getValue() 调用总是返回 null,即使我 select 是列表中的一个项目。 现在我问你们,链条中缺失的部分在哪里?我是否正确地进行了数据绑定。我是否以错误的方式访问元素?提前致谢。

value 属性存储 af:selectOneChoice 组件的输出。由于您没有添加它,返回的值为空。