2013-11-27 25 views
1

我在填充使用EnumMap的作爲綁定網格有一個問題:ZK ZUL迭代一個EnumMap的填充柵格

<grid sizedByContent="true" span="true" model="@bind(vm.pendingRequests[RequestType.RETURN])" 
emptyMessage="Nessuna richiesta trovata" height="100%" width="100%"> 

在視圖模型有地圖的聲明:

private Map<RequestType, List<PendingRequest>> pendingRequests; 

如果請求類型是一個枚舉:

public enum RequestType { 
    EXIT("exit"), 
    RETURN("return"), 
    PARKING("park"); 

    private final String description; 

    private RequestType(String description) { 
     this.description = description; 
    } 

    public String getDescription() { 
     return description; 
    } 

    public static RequestType getEnum(String value) { 
     if (value == null) { 
      throw new IllegalArgumentException(); 
     } 
     for (RequestType v : values()) { 
      if (value.equalsIgnoreCase(v.getDescription())) { 
       return v; 
      } 
     } 
     throw new IllegalArgumentException(); 
    } 
} 

你知道我錯了,在使用EnumMap的填充網格並綁定?

非常感謝!

+0

是否有來自ZK的錯誤消息? – bidifx

+0

ZK沒有錯誤,因爲地圖中沒有數據,它顯示爲空信息。 –

+0

你有'pendingRequests'的公共getter嗎? – bidifx

回答

0

public EnumType getTypeItem() { 
    return EnumType.Item; 
} 
  • 使用此getter遵循@bidifx的建議,我以這種方式更改了zul:

    <grid sizedByContent="true" span="true" model="@load(vm.getPendingRequests('RETURN'))" 
         emptyMessage="Nessuna richiesta trovata" height="100%" width="100%"> 
    

    並在視圖模式,我創建了一個直接返回的列表中ZUL的方法:

    public List<PendingRequest> getPendingRequests(String stype) { 
         RequestType type = RequestType.valueOf(stype); 
         return pendingRequests.get(type); 
        } 
    

    這爲我工作。 謝謝大家!

  • 2

    所以在這裏,我們去:

    你不能直接訪問static類成員。這也適用於在某種程度上相同的enum。所以,你必須使用這個小解決辦法...

    1. 創建一個getter您枚舉項目:在您的ZUL

      <label value="@load(vm.typeItem)">