【发布时间】:2021-10-18 09:33:40
【问题描述】:
我目前正在使用 Jdev v12.2.1.4.0 (Oracle 12c) 修改 ADF Fusion Web 应用程序。
在其中一个 jsf 页面上,我在表格列中有一个 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 属性,因为进程没有必要在这里选择一个值。
我的 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 页面时,表格内的 SelectOneChoices 会被渲染,并且所有预期的项目都会被登记。每当我尝试访问 SelectOneChoice 的选定项目时,我都会遇到问题。
当我点击页面上的按钮时,我想读取 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,即使我从列表中选择了一个项目。
现在我问你们,链条中缺少的部分在哪里?我是否正确地进行了数据绑定。我是否以错误的方式访问元素?提前致谢。
【问题讨论】:
-
您可以尝试在 af:selectOneChoice 上添加 value 属性,并检查 newValue 是否存储在 value 属性中
-
@SaiPatil 我假设我必须在我的 bean 中创建一个变量来存储它,对吧?它必须是哪种类型?或者我可以直接从 bean 访问 value 属性吗?
-
对,变量必须在bean中创建,value属性是Object类型。在值更改侦听器的值属性中以及在提交之后打印数据,如果您有任何类似的功能。
-
添加 value 属性后,bindingErrorCaseSelectOneChoice.getValue 应该理想地返回设置值。
-
我测试了在 valuechangelistener 方法中获取所选值并检索到一些东西:D。似乎 value 属性是缺失的部分。不幸的是,它似乎是 id 而不是价值,但我已经有了一个想法去弄清楚。你可以写一个答案;)
标签: java oracle jdeveloper