2011-05-24 52 views

回答

2

您需要維護這些值在backing bean中的映射。

private Map<Long, String> foods; 

public Bean() { 
    foods = new HashMap<Long, String>(); 
    foods.put(1L, "Pizza"); 
    foods.put(2L, "Cheese"); 
    foods.put(3L, "Cake"); 
    // ... 
} 

public Map<Long, String> getFoods() { 
    return foods; 
} 

然後你就可以得到它的如下

<h:dataTable value="#{bean.items}" var="item"> 
    <h:column> 
     <h:outputText value="#{bean.foods[item.number]}" /> 
    </h:column> 
</h:dataTable> 

#{item.number}應該返回所需數量Long

+0

@BalusC:感謝您的快速回復......您的解決方案工作:) – user1234 2011-05-24 19:48:12

+0

@BalusC:最初我在考慮使用messages.properties。有沒有可能爲此目的使用屬性文件?請讓我知道 – user1234 2011-05-24 19:49:37

+0

不客氣。當然,只需用'Properties'替換'Map '。自從'Properties'擴展了'Map '以後,它將同樣工作。 '#{item.number}'現在不一定需要是'Long'。 'String'也很好。 – BalusC 2011-05-24 19:55:08

相關問題