2016-08-04 91 views
0

我正在處理的東西似乎是一項微不足道的任務,但尚未找到解決方案:如何訪問RichSelectOneChoice上的文本?我只發現richSelectOneChoice.getValue()valueChangeEvent.getNewValue()ADF RichSelectOneChoice獲取文本(標籤)

的值但是,如何訪問實際文本?

我的最後一次嘗試是這樣的:

private RichSelectOneChoice selClaim; 

public void claimTypeVCL(ValueChangeEvent ve){ 
    Map s = selClaim.getAttributes(); 
    Object ss = s.get(ve.getNewValue()); 
    System.out.println(ss); 
} 

目前控制檯輸出爲null爲相應的值,無論選擇是什麼。

綁定到RichSelectOneChoice對象的ADF組件被創建爲具有內部元素的組件。

我也嘗試由Frank Nimphius使用適當的對象類型(RichSelectOneChoice)這裏提出https://community.oracle.com/thread/1050821的解決方案,但如果該條款不執行,因爲孩子不是instanceof RichSelectOneChoice的建議,而是javax.faces.component.UISelectItem和此類不包括getLabel()方法,並且運行代碼實際上會拋出大量與將對象轉換爲目標類型相關的錯誤,或者在嘗試訪問標籤時拋出空指針。

+0

您是否試圖與UISelectItem對象的getAttribute(key)方法?類似於selectItem.gettAttribute(「description」) –

+0

UISelectItem類沒有getAttribute()方法,只有getAttributes()方法返回Map 。我會試試這個。 – codeSwim

回答

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