primefaces - Strange behaviour of ArrayList in jsf -
i'm developing web app using jsf. trying display property "brandname" of element index 0 in arraylist "materialssummarybean.electrolysermateriallotlist" , property elements using "c:foreach".
<br/> #{materialssummarybean.electrolysermateriallotlist.get(0).material.material.brandname} <br/> #{materialssummarybean.electrolysermateriallotlist.get(0).material.material.brandname} <br/> #{materialssummarybean.electrolysermateriallotlist.get(0).material.material.brandname} <br/> #{materialssummarybean.electrolysermateriallotlist.get(0).material.material.brandname} <br/> #{materialssummarybean.electrolysermateriallotlist.get(0).material.material.brandname} <br/> #{materialssummarybean.electrolysermateriallotlist.get(0).material.material.brandname} <br/> #{materialssummarybean.electrolysermateriallotlist.get(0).material.material.brandname} <br/> #{materialssummarybean.electrolysermateriallotlist.get(0).material.material.brandname} <br/> <hr/> <c:foreach items="#{materialssummarybean.electrolysermateriallotlist}" var="item" varstatus="loop"> #{item.material.material.brandname} <br/> #{item.material.material.brandname} <br/> #{item.material.material.brandname} <br/> #{item.material.material.brandname} <br/> #{item.material.material.brandname} <br/> #{item.material.material.brandname} <br/> #{item.material.material.brandname} <br/> <hr/> </c:foreach>
in result have absolutly randomize list of values element index 0:
ШБ-5 ЗШБ класс 4 МШ-39 ЗШБ класс 4 МШ-39 КПД-400И ШБ-5 МШ-39
for elements in list:
ЗШБ класс 4 ЗШБ класс 4 КПД-400И ЗШБ класс 4 ШБ-5 МШ-39 ЗШБ класс 4 <hr /> ЗШБ класс 4 ЗШБ класс 4 МШ-39 КПД-400И ЗШБ класс 4 ШБ-5 МШ-39 <hr /> МШ-39 КПД-400И ЗШБ класс 4 КПД-400И ЗШБ класс 4 ШБ-5 МШ-39 <hr /> ШБ-5 ЗШБ класс 4 МШ-39 МШ-39 ШБ-5 КПД-400И МШ-39 <hr />
and don't have idea , problem.
materialssummarybean method "getelectrolysermateriallotlist":
public list<materiallotsummarydata> getelectrolysermateriallotlist() { materiallotfilter materiallotfilter = new materiallotfilter(); materiallotfilter.setelectrolyserid(id); return materialservice.getmateriallotbyelectrolyserid(materiallotfilter); }
and "getmateriallotbyelectrolyserid" method:
public list<materiallotsummarydata> getmateriallotbyelectrolyserid(materiallotfilter materiallotfilter) { long electrolyserid = materiallotfilter.getelectrolyserid(); if (electrolyserid == null) { throw new illegalargumentexception("electrolyser id cannot null."); } typedquery<unit> queryunit = em.createquery( "select u unit u u.electrolyser.id = :selectedelectrolyser", unit.class) .setparameter("selectedelectrolyser", electrolyserid); list<unit> unitlist = queryunit.getresultlist(); hashset<materiallot> materiallotlist = new hashset<materiallot>(); hashmap<long, double> materiallotusagemap = new hashmap<long, double>(); (unit unit : unitlist) { materiallot currentmateriallot = unit.getmateriallot(); if (currentmateriallot == null) continue; materiallotlist.add(currentmateriallot); double usage = unit.getactualmaterial().getamount(); if (!materiallotusagemap.containskey(currentmateriallot.getid())) { materiallotusagemap.put(currentmateriallot.getid(), (usage == null) ? 0 : usage); } else { if(usage == null) continue; double currentusage = materiallotusagemap.get(currentmateriallot.getid()); materiallotusagemap.put(currentmateriallot.getid(), currentusage + usage); } } list<materiallotdata> result = mapper.createlist(materiallotlist, materiallotdata.class); materiallotsummarydata summarydata; arraylist<materiallotsummarydata> summaries = new arraylist<materiallotsummarydata>(); (materiallotdata materiallot : result) { if (materiallotusagemap.containskey(materiallot.getid())) { summarydata = new materiallotsummarydata(); summarydata.setid(materiallot.getid()); summarydata.setacceptancedate(materiallot.getacceptancedate()); summarydata.setlotnumber(materiallot.getlotnumber()); summarydata.setmaterial(materiallot.getactualmaterial()); summarydata.setnumber(materiallot.getnumber()); summarydata.setmanufacturer(materiallot.getmanufacturer()); double usage = materiallotusagemap.get(materiallot.getid()); summarydata.setusage(usage); summaries.add(summarydata); materiallotusagemap.remove(materiallot.getid()); } } return summaries; }
service method called each access of electrolysermateriallotlist
, list prepared accessing database , doing same operations again single item access. should avoid doing so. basically, can use null check in getter method.
public list<materiallotsummarydata> getelectrolysermateriallotlist() { if(electrolysermateriallotlist == null) { materiallotfilter materiallotfilter = new materiallotfilter(); materiallotfilter.setelectrolyserid(id); electrolysermateriallotlist = materialservice.getmateriallotbyelectrolyserid(materiallotfilter); } return electrolysermateriallotlist; }
Comments
Post a Comment