2016-11-29 25 views
0

DynamicJasper中的Hashmap屬性的動態列。可能嗎?來自列表<?>屬性的列。在動態碧玉中可能嗎?

嗨,我真的很新的動態賈斯珀。我遇到了一些應該來自Hashmap屬性的列的問題。我把一個例子再清楚不過了:

class Product { 
private String name; 
private String price; 
private String whatever; 
private Hashmap<String,String> comments; 
} 

我的數據源是一個產品List<Product>;

|__name___|___price___|_____whatever_____|______First item inside the comments list_____|___Second item inside the comments list____|___N item inside the comments list __| 

列的名稱將與hashmap.and中的鍵相同,值是散列表的值。 每個對象(產品)有不同的意見(值),但同樣keys.for例如一個HashMap:

product1: name1,price1, hashmap: ("quality","good")("easyToUse","yes") 
product2: name2,price2, hashmap: ("quality","bad")("easyToUse","no") 

,報告應該是這樣的:

|__ name_______|______price _____|_____quality_____|______easyToUse______| 

|___name1_____|______price1_____|______ good_____|______ yes___________| 

|___name2_____|______price2_____|______ bad______|______ no____________| 

是否有可能或者我應該嘗試另一種方法? 如何動態創建列並將其設置爲正確值?

問候

+0

你是什麼意思列?你有沒有試過任何代碼? –

+0

您的意思是'toString'方法,您首先打印名稱,值,任何內容,然後是評論列表? –

+0

@RimonMostafiz我發現這個:http://www.dynamicreports.org/forum/viewtopic.php?f=1&t=170 但我無法使用它。 =( – melika

回答

0

你可以做的產品中的每一個關鍵的迭代,爲每一個打印的產品,其價格的關鍵和相應的值的名稱。

for(Product p : Products){ 
    for(String key : p.comments.keySet()){ 
     System.out.println(p.name +", " + p.price", "+ key +" " + p.comments.get(key)); 
    } 
} 
+0

謝謝,但它不像散列圖上的迭代那麼簡單我想創建列動態Jasper動態,它不會用一個簡單的itteration =( – melika