jsf 2 - Dynamic datatable for columns and rows jsf (JSF2) -
i followed below link added columns , row data dynamic, little confused on how show on xhtml. help
http://balusc.blogspot.com/2006/06/using-datatables.html#populatedynamicdatatable
list<string> strlist = new arraylist<string>(); list<list<string>> dynamiclistynamiclist = new arraylist<list<string>>(); strlist.add("name"); strlist.add("ssn"); for(string columnname : columnnameslist){ strlist.add(columnname); } list<string> rowdata = new arraylist<string>(); for(string otherlist : listdata){ try { rowdata.add(otherlist.getname()); rowdata.add(otherlist.getid()); if(otherlist.getamount() != null){ for(bigdecimal amount : otherlist.getamount()){ if(amount != null){ rowdata.add(amount.tostring()); }else{ rowdata.add(""); } } }else{ for(string s : strlist){ rowdata.add(""); } } } catch (exception e) { // todo: handle exception e.printstacktrace(); } dynamiclistynamiclist.add(arrays.aslist(rowdata.toarray(new string[rowdata.size()] ))); } string[] strarray = new string[strlist.size()]; dynamicheaders = strlist.toarray(strarray ); populatedynamicdatatable(dynamiclistynamiclist); private void populatedynamicdatatable(list<list<string>> dynamiclist2){ htmldatatable dynamicdatatable = new htmldatatable(); (int = 0; < dynamiclist2.get(0).size(); i++) { htmlcolumn column = new htmlcolumn(); dynamicdatatable.getchildren().add(column); htmloutputtext header = new htmloutputtext(); header.setvalue(createvalueexpression("#{dynamicitemcolumn[" + dynamicheaders[i] + "]}", string.class)); column.setheader(header); htmloutputtext output = new htmloutputtext(); output.setvalueexpression("value", createvalueexpression("#{dynamicitem[" + + "]}", string.class)); column.getchildren().add(output); } dynamicdatatablegroup = new htmlpanelgroup(); dynamicdatatablegroup.getchildren().add(dynamicdatatable); setdynamiclist(dynamiclist2);
every thing works fine data being added, wasnt sure , apologies, how iterate in jsf page(xhtml), show relvant columna nd rowdata..
Comments
Post a Comment