【发布时间】:2016-08-04 08:15:51
【问题描述】:
我正在处理一些看似微不足道但尚未找到解决方案的任务:如何访问 RichSelectOneChoice 上的文本?我只找到了 richSelectOneChoice.getValue() 和 valueChangeEvent.getNewValue() 的值
但是,如何访问实际的文本呢?
我最后一次尝试是这样的:
private RichSelectOneChoice selClaim;
public void claimTypeVCL(ValueChangeEvent ve){
Map s = selClaim.getAttributes();
Object ss = s.get(ve.getNewValue());
System.out.println(ss);
}
此时无论选择什么,控制台输出对应的值都是空的。
绑定到 RichSelectOneChoice 对象的 ADF 组件被创建为具有内部元素的组件。
我还尝试了 Frank Nimphius 在这里提出的解决方案 https://community.oracle.com/thread/1050821 与正确的对象类型 (RichSelectOneChoice) 但 if 子句没有执行,因为孩子不是建议的 instanceof RichSelectOneChoice 而是 javax.faces.component.UISelectItem 和此类不包含 getLabel() 方法,并且运行代码实际上会引发大量错误,这些错误与将对象转换为目标类型或尝试访问标签时的空指针有关。
【问题讨论】:
-
您是否尝试过使用 UISelectItem 对象的 getAttribute(key) 方法?像 selectItem.gettAttribute("description")
-
UISelectItem 类没有getAttribute() 方法,只有getAttributes() 方法,它返回一个Map
。我会试试这个。
标签: jsf oracle-adf