Displaying Hashmap keys and values in a primefaces DataTable

前端 未结 1 1464
無奈伤痛
無奈伤痛 2020-12-08 15:28

I\'m trying to display a Hashmap in a DataTable, here\'s what i\'m trying to do : I\'ll have a select menu of some products, and an input text for quantity, an \"ajaxified\"

1条回答
  •  佛祖请我去吃肉
    2020-12-08 15:46

    You create Class like this:

    public class Product{
        private int id;
        private String productName;
        private int quantitiy;
    
        // add getters setters here
    }
    
    // add product id to map key
    Map myMap = new HashMap();
    
    public Map getProductMap() {
       return myMap;
    }
    
    
    public List getProducts() {
       return new ArrayList(myMap.values()_;
    }
    

    Add datatable value to getProducts() List

    Otherwise, product as a map key then,

    Map myMap = new HashMap();
    
    public List> getProducts() {
        Set> productSet = 
                         myMap.entrySet();
        return new ArrayList>(productSet);
    }
    

    write primeface page like this way,

    
       
          
       
       
           
       
    
    

    0 讨论(0)
提交回复
热议问题