【问题标题】:ADF RichSelectOneChoice get text (label)ADF RichSelectOneChoice 获取文本(标签)
【发布时间】: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


【解决方案1】:

使用 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();
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多