java - How to Bind two class in Datatable -
i have problem binding 2 java classes 1 datatable component. have 2 managed beans product , order
product source:
public class product { private integer id; private string kategoria; private string symbol; private string opis; private double cena; //getters , setters //..... //hashcode, equals methods }
and order source:
public class order { private product produkt; private integer quantity; public order() {} public order(product product, integer quantity) { this.produkt = product; this.quantity = quantity; } public void setproduct(product produkt) { this.produkt = produkt; } public product getprodukt() { homecoming produkt; } public void setquantity(integer quantity) { this.quantity = quantity; } public integer getquantity() { homecoming quantity; } }
my question is: how bind class order
<h:datatable />
component have poduct values , quantity numer. have created productbean class setorder , getorder methods
public list<orderline> getlist() { list<orderline> l = new arraylist<orderline>(); for(orderline ol : list) { l.add(ol); } homecoming l; } public void setlist(set<orderline> list) { if (this.list.isempty() ) this.list = list; else { iterator<orderline> = this.list.iterator(); for(orderline p : list) { while(it.hasnext()) { if(it.next().equals(p)) { this.list.add(p); } } } } }
i'm doing conversion set list, because thought more convenient retrieve info list.
why don't want utilize mutual approach?
<h:datatable value="#{productbean.getlist}" var="o"> <h:column> #{o.quantity} </h:column> <h:column> #{o.produkt.kategoria} </h:column> ... <h:column> #{o.produkt.cena} </h:column> </h:datatable>
you can access product fields through order object.
updwhat have do:
specify getters , setters fields of order , product classes specify getter , setter set of orders create set, set orders there iterate on showed before java jsf datatable
No comments:
Post a Comment