2010-07-26 13 views
1

如果我想一個h:selectmanycheckbox的價值屬性綁定到一個地圖,用JSF 2.0.3的裏我會做類似下面ICEfaces的2測試版1:結合selectmanycheckbox到地圖引發轉換錯誤

豆:

private Map<String, String[]> values = new HashMap<String, String[]>(); 

public Map<String, String[]> getValues() { 
    return values; 
} 

public void setValues(Map<String, String[]> values) { 
    this.values = values; 
} 

和XHTML頁面:

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core"> 
<h:head> 
    <title>Facelet Title</title> 
</h:head> 
<h:body> 

    <h:form> 
     <h:selectManyCheckbox 
      id="test" 
      value="#{testController.values['foo']}"> 
       <f:selectItem itemLabel="1" itemValue="1_1" /> 
       <f:selectItem itemLabel="2" itemValue="1_2" /> 
       <f:selectItem itemLabel="3" itemValue="1_3" /> 
       <f:selectItem itemLabel="4" itemValue="1_4" />      
     </h:selectManyCheckbox>   
     <h:commandButton value="Send" /> 

    </h:form> 

</h:body> 

這可以正常工作,但在我的應用程序中,我需要對每個複選框的位置進行更多控制,因此我將標準<h:selectManyCheckbox>標籤替換爲其相應的冰面標籤<ice:selectManyCheckbox><ice:checkbox>
豆子保持不變和XHTML的網頁現在看起來像這樣:

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:ice="http://www.icesoft.com/icefaces/component" 
    xmlns:f="http://java.sun.com/jsf/core"> 
<h:head> 
    <title>Facelet Title</title> 
</h:head> 
<h:body> 
    <h:form> 
     <ice:selectManyCheckbox 
      id="test" 
      layout="spread" 
      value="#{testController.values['foo']}"> 
       <f:selectItem itemLabel="1" itemValue="1_1" /> 
       <f:selectItem itemLabel="2" itemValue="1_2" /> 
       <f:selectItem itemLabel="3" itemValue="1_3" /> 
       <f:selectItem itemLabel="4" itemValue="1_4" />      
     </ice:selectManyCheckbox>   
     <table border="1"> 
      <tr> 
       <td><ice:checkbox id="c1" for="test" index="0" /></td> 
       <td><ice:checkbox id="c2" for="test" index="1" /></td> 
      </tr> 
      <tr> 
       <td><ice:checkbox id="c3" for="test" index="2" /></td> 
       <td><ice:checkbox id="c4" for="test" index="3" /></td> 
      </tr> 
     </table> 
     <h:commandButton value="Senden" />    
    </h:form> 

</h:body> 

現在,每當我送的形式,我得到一個轉換錯誤,我想不通爲什麼。

如果我將<ice:selectManyCheckbox>的值屬性綁定到一個簡單的stringarray,它會分叉,但是因爲我不知道有多少checkbox組,我需要它來處理一個map。

我在tomcat 6.0.26上使用了icefaces 2.0.0 beta 1和sun ri 2.0.3以及el 2.2。

有沒有人知道我的問題的解決方案?

回答

0

您可以嘗試放置儘可能多的虛擬mapelemts,因爲您需要「初始化」您的地圖。

+0

這似乎是做的伎倆,但考慮到我不必這樣做與ri,我想它可以被視爲一個錯誤。 – greg 2010-07-28 07:13:44

+0

也許你可以bugreport這個......他們喜歡在beta階段閱讀bugreports :) – 2010-07-28 08:34:22

0

您是否嘗試實施轉換器?

+0

感謝您的快速響應。 其實我做了,但是很奇怪。 我實現了一個自定義轉換器,並且包含一個println()以查看其進度,並且在多次成功調用getAsString()方法的同時,不會調用getAsObject()方法。 有什麼想法? – greg 2010-07-26 15:46:27

+0

不是真的,但也許這是不正確的方式.. – 2010-07-27 15:11:08

2

前一段Ifaced完全相同的問題,我意識到,這是當你在selectManyCheckbox設置爲值映射一個怪異的行爲,所以我所做的是不是使用Map<Integer,List<SomeValues>>Map<Integer,SomeValuesContainer>和內部的I類設置List<SomeValues>作爲一個屬性:

class SomeValuesContainer implement Serializable{ 
    List<SomeValues> someValuesList; 
    SomeValues getSomeValueList(){ 
     return someValuesList; 
    } 

    void setSomeValuesList(List<SomeValues> someValueList){ 
      this.someValuesList = someValuesList; 
    } 
} 

所以我可以從這樣的觀點訪問:

<ice:selectManyCheckbox 
     id="test" 
     layout="spread" 
     value="#{testController.values['foo'].someValuesList}"> 

這是因爲該selectManyCheckbox值需要看價值作爲一種財產,而不是一種功能。

相關問題