jsf 2 - How to pass a List to javascript in JSF -
i struggling jsf project. in service, retrieve list of custom object (here sales), , have pass jsf view, javascript, make graphs.
my problem is, don't understand how send data controller (my managed beans) view, , tag use in view retrieve in javascript.
i think can pass data this, i'm not sure
public string passdata() {     list<sales> bestselling = saleservice.getbestsellingproduct(null, null, null, null);     list<sales> worstselling = saleservice.getworstsellingproduct(null, null, null, null);      facescontext.getcurrentinstance().getexternalcontext().getsessionmap().put("bestselling", bestselling);     facescontext.getcurrentinstance().getexternalcontext().getsessionmap().put("worstselling", worstselling);      return "./all.jsf?faces-redirect=true"; }      
you need create json object you'll assign javascript variable. create json may find useful incorporate library gson.
so, it'll like:
var sales = #{bean.jsonlist};   with bean#getjsonlist as:
public string getjsonlist() {      return (sales == null) ? "" : new gson.tojson(sales); }   just don't forget script such assignment must handled facesservlet.
Comments
Post a Comment