2012-09-25 21 views
0

我創建了一個頂點:dynamicComponent,它根據存儲的數據創建複選框。inputCheckBox不會從Apex設置

複選框的創建如下:

Component.Apex.inputCheckbox chkBox = new Component.Apex.inputCheckbox(); 
if (myMap.get(myList[i]) == true) 
    chkBox.selected = true; 

但是當我嘗試以顯示我的VF頁,它顯示:

System.VisualforceException: Invalid value for property selected: java.lang.String cannot be cast to java.lang.Boolean 

我試圖設置「chkBox.selected」與不同的值(例如,字符串'真')我無法保存我的控制器。

感謝您的幫助。

回答

0

而不是創造如上爲什麼我們不能創建CheckBox組件類似下面

public Boolean chkBox{ 
    get{ 
     if(myMap.get(myList[i]) == true){ 
      return true; 
     } 
      return false;    
    } 
    set; 

在Visualforce頁面,我們可以如下編寫頂點組成的

<apex:outputLabel value="Check Box Label"/> <apex:inputCheckBox value="{!chkBox}"><apex:actionSupport event="onclick" rerender="TheBlock" status="showCredentialing" /> 

的錯誤也可能是由於由於VF錯誤沒有行號,所以在視覺力頁面上出現的其他輸出字段ERROR。

我試圖在Visualforce頁面中實現一個獨立的Component.Apex.inputCheckbox。請嘗試下面的代碼

控制器

  public class testcontroller { 
     public Component.Apex.inputCheckbox chkBox { get; set; } 
     public Component.Apex.inputCheckbox dyCheckbox; 
     public PageReference chkBox3() { 
      this.chkBox = new Component.Apex.inputCheckbox(); 
      System.debug('Here is Test'); 
      this.chkBox.value = true;  
      return null; 
      } 
     public String chkBox2 { get; set; } 
     public testcontroller(){ 
      this.chkBox2 = 'false'; 
     } 
     public Component.Apex.inputCheckbox getInputCheckbox() { 
      Component.Apex.inputCheckbox dyCheckbox = new Component.Apex.inputCheckbox(); 
      dyCheckbox.value = 'true'; 
      return dyCheckbox; 
      } 
     } 

VISUALFORCE PAGE

<apex:page controller="testcontroller"> 
    <!-- Begin Default Content REMOVE THIS --> 
    <h1>Congratulations</h1> 
    This is your new Page: test 
    <apex:form > 
    <apex:outputLabel value="Check Box Label"/> 
    <apex:inputCheckBox value="{!chkBox2}"/> 

       <apex:dynamicComponent componentValue="{!InputCheckbox}" /> 


    <apex:commandButton value="sd" action="{!chkBox3}" title="asdf"/> 
    </apex:form> 

    <!-- End Default Content REMOVE THIS --> 
</apex:page> 
+0

我用一個頂點組成部分,因爲我無法顯示我的複選框我直接需要他們在VF的方式:我需要在表格中顯示可變數量的複選框(標題+ 2行「n」複選框)。我確信錯誤來自「chkBox.selected = true;」 :當這一行被評論時,我沒有更多的錯誤。 – Plato

+0

Hi Plato,我試圖在Visualforce頁面中實現一個獨立的Component.Apex.inputCheckbox。請嘗試下面的代碼 –

+0

非常感謝!我會嘗試一下你的代碼:這似乎是解決方案的途徑。 – Plato