2013-09-27 46 views
0

我正在使用JDev 12c。Oracle ADF複選框丟失狀態

我想實現一些的複選框,這樣的單選按鈕的工作:

http://jsfiddle.net/TTZqa/

但我不能使它發揮作用。

我有一個表格 - t2 - 包含三行,其中每一行都有一個複選框。當用戶選擇複選框時,應該檢查它,如果另一個複選框已經被選中,它應該被取消選中。

應該只能檢查一行,並且在提交時必須檢查一行。

我有我的選擇框下面的聽衆:

<af:clientListener type="click" method="sayHello"/> 

和我的JS函數看起來像這樣:

function sayHello(event) { 
      event.cancel(); 
      var source = event.getSource(); 

      var chk1 = AdfPage.PAGE.findComponentByAbsoluteId('t2:0:sbc1'); 
      var chk2 = AdfPage.PAGE.findComponentByAbsoluteId('t2:1:sbc1'); 
      var chk3 = AdfPage.PAGE.findComponentByAbsoluteId('t2:2:sbc1'); 

      if (source == chk1) { 
       chk1.setValue(true); 
       chk2.setValue(false); 
       chk3.setValue(false); 
      } 
      else if (source == chk2) { 
       chk1.setValue(false); 
       chk2.setValue(true); 
       chk3.setValue(false); 
      } 
      else if (source == chk3) { 
       chk3.setValue(true); 
       chk2.setValue(false); 
       chk1.setValue(false); 
      } 
     } 

我知道,當點擊任一複選框,當函數被調用但所有的盒子都沒有檢查。我可以看到複選標記短暫閃爍但不會停留。

如果我打電話給一個空的javascript函數,用戶可以點擊所有三個複選框,並且複選標記保留在框中,但它們不是相互排斥的,它按我的預期工作。

但是,當我寫這樣的功能:

function sayHello(event) { 
      event.cancel(); 
      var source = event.getSource(); 
      var chk1 = AdfPage.PAGE.findComponentByAbsoluteId('t2:0:sbc1'); 

}

複選標記隨即消失。我試着刪除'event.cancel();}。但它沒有任何區別。

我甚至可以用相同形式的輸入字段替換我發現的組件,並將文本添加到它。文本出現在輸入字段中,但複選框會立即從複選框中消失。

我研究:

http://technology.amis.nl/2013/05/07/adf-client-side-architecture-select-all/

我到底錯在這裏做什麼?

感謝

編輯:

我創建了以下非常簡單的頁面:

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE html> 
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich"> 
<af:document title="untitled2.jsf" id="d1"> 
    <af:messages id="m1"/> 
    <af:resource type="javascript">  
     function sayHello(event) { 
      event.cancel(); 
      var source = event.getSource(); 
      var chk1 = AdfPage.PAGE.findComponentByAbsoluteId('sbc1'); 
      var chk2 = AdfPage.PAGE.findComponentByAbsoluteId('sbc2'); 
      var chk3 = AdfPage.PAGE.findComponentByAbsoluteId('sbc3'); 
      if (source == chk1) { 
       chk1.setValue(true); 
       chk2.setValue(false); 
       chk3.setValue(false); 
      } 
      else if (source == chk2) { 
       chk2.setValue(true); 
       chk1.setValue(false); 
       chk3.setValue(false); 
      } 
      else if (source == chk3) { 
       chk3.setValue(true); 
       chk2.setValue(false); 
       chk1.setValue(false); 
      }   
     } 
    </af:resource> 
    <af:form id="f1"> 
     <af:panelGridLayout id="pgl1"> 
      <af:gridRow height="100%" id="gr1"> 
       <af:gridCell width="100%" halign="stretch" valign="stretch" id="gc1"> 
        <!-- Content --> 
        <af:selectBooleanCheckbox label="Label1" id="sbc1" clientComponent="true"> 
         <af:clientListener type="click" method="sayHello"/> 
        </af:selectBooleanCheckbox> 
        <af:selectBooleanCheckbox label="Label1" id="sbc2" clientComponent="true"> 
         <af:clientListener type="click" method="sayHello"/> 
        </af:selectBooleanCheckbox> 
        <af:selectBooleanCheckbox label="Label1" id="sbc3" clientComponent="true"> 
         <af:clientListener type="click" method="sayHello"/> 
        </af:selectBooleanCheckbox> 
       </af:gridCell> 
      </af:gridRow> 
     </af:panelGridLayout> 
    </af:form> 
</af:document> 

,我看到完全一樣的奇怪的行爲。 ....我似乎無法選中複選框。複選標記消失。

任何輸入?我被困在這裏。

/ 金

+0

你嘗試以提醒您收到的值。例如,你嘗試使alert(source.getValue())成爲例子嗎?看看你收到了什麼。 你也確定chk1,chk2和chk3實際上是成功創建的。 我相信你的比較應該基於Id,而不是等於 source.getId()== chk1.getId() –

回答

0

嘗試使用這樣的替代JavaScript函數:

<af:resource type="javascript">  
    function sayHello(event) { 
     var source = event.getSource(); 
     var chk1 = source.findComponent('sbc1'); 
     var chk2 = source.findComponent('sbc2'); 
     var chk3 = source.findComponent('sbc3'); 
     if (source.getId() == chk1.getId()) { 
      chk1.setValue(true); 
      chk2.setValue(false); 
      chk3.setValue(false); 
     } 
     else if (source.getId() == chk2.getId()) { 
      chk2.setValue(true); 
      chk1.setValue(false); 
      chk3.setValue(false); 
     } 
     else if (source.getId() == chk3.getId()) { 
      chk3.setValue(true); 
      chk2.setValue(false); 
      chk1.setValue(false); 
     }   
     event.cancel(); 
    } 
</af:resource>