ADF RichSelectOneChoice获取文字(标签)

时间:2016-08-04 08:15:51

标签: jsf oracle-adf

我处理的事情似乎是一项微不足道的任务,但还没有找到解决方案:如何在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()方法,并且运行代码实际上会抛出与将对象转换为目标类型相关的各种错误或者试图访问标签。

1 个答案:

答案 0 :(得分:0)

使用UISelectionItem对象及其getItemValue()和getItemLabel()方法解决它,而不是getLabel()或getValue(),后者可用但未呈现预期结果。

工作代码如下所示:

public String selectedOptionStr;
public void socClaimTypeVCL(ValueChangeEvent ve){
    selectedOptionStr = "";
    RichSelectOneChoice sct = (RichSelectOneChoice)ve.getSource();
    List childList = sct.getChildren();
    for (int i = 0; i < childList.size(); i++) {
        if (childList.get(i) instanceof javax.faces.component.UISelectItem) {                
            javax.faces.component.UISelectItem csi = (javax.faces.component.UISelectItem) childList.get(i);
            if (csi.getItemValue().toString() == ve.getNewValue().toString()) {
                selectedOptionStr = csi.getItemLabel();
            }
        }
    }
}