</pre>此次培训学员用的版本是12c,在使用JobView做多选下拉的例子的时候出现字符串转Integer的错误提示:代码如下:<p></p><p></p><p></p><pre code_snippet_id="1607578" snippet_file_name="blog_20160312_2_3673997" name="code" class="java"> try {
BindingContext bc = BindingContext.getCurrent();
BindingContainer bindingContainer = bc.getCurrentBindingsEntry();
JUCtrlListBinding jubinding = (JUCtrlListBinding) bindingContainer.get("JobsView1");
// System.out.println(jubinding.getSelectedValues());
Object[] objs = jubinding.getSelectedValues();
int [] indexs = jubinding.getSelectedIndices();
// System.out.println(indexs);
for (int i:indexs) {
System.out.println("aaaaaa:"+jubinding.getRowAtRangeIndex(i).getAttribute("JobTitle"));
}
for (Object obj : objs) {
System.out.println("bbbbbbbbb:"+obj);
}
jubinding.clearSelectedIndices();
} catch (Exception e) {
// TODO: Add catch code
e.printStackTrace();
}
return null;
原因出在多选的时候ADF默认下拉取的是对象,而取对象的时候要根据索引值去找,我们把取值模式改成索引上面的代码就不会出现转型错误了:
<list IterBinding="JobsView1Iterator" ListOperMode="multiSelect" ListIter="JobsView1Iterator" id="JobsView1"
SelectItemValueMode="ListIndex">
<AttrNames>
<Item Value="JobId"/>
</AttrNames>
<ListDisplayAttrNames>
<Item Value="JobTitle"/>
</ListDisplayAttrNames>
</list>
SelectItemValueMode的默认值是slectObject,改成ListIndex即可.如果VO的主键是Number或可以转换成Number类型则不要改变这个属性的设置!
另外,最新的版本是12.2.1,非常不建议使用这个版本,改动太大了!特别是在数据验证方面,它提示的模式非常不适合由国人的习惯。