i have problem getting primefaces dynamic image working. think doing in example on primefaces showcase image isn't loaded on page. managed bean looks follows.
@managedbean(name = "statisticsbean") @nonescoped public class statisticsbean { private wmcuser user; private basicgroup group; private list<gameprogressstatistics> linechartstats; private list<userstatistics> userstatistics; private static final logger logger = logger.getlogger(statisticsbean.class.getname()); public statisticsbean() { ... createuserstatistics(); } private void createuserstatistics() { list<wmcuser> users = grouphelper.getnondeletedmembers(group); (wmcuser wmcuser : users) { userstatistics.add(new userstatistics( wmcuser.getstatuser().getmakecount(), wmcuser.getstatuser().getgamesplayed(), wmcuser.getfirstname(), wmcuser.getlastname())); } } public class userstatistics { private int makecount; private int gamecount; private string firstname; private string lastname; private streamedcontent thermochart; public userstatistics(int makecount, int gamecount, string firstname, string lastname) { this.makecount = makecount; this.gamecount = gamecount; this.firstname = firstname; this.lastname = lastname; try { thermometerplot plot = new thermometerplot(createthermometerdataset()); file chartfile = new file("dynamichart"); jfreechart chart = new jfreechart(plot); chartutilities.savechartaspng(chartfile, chart, 50, 50); thermochart = new defaultstreamedcontent(new fileinputstream(chartfile), "image/png"); } catch (exception e) { logger.severe(e.getmessage()); } ..... } ..... }
the jsf page looks this
<h:form id="stats"> <p:datatable id="statstable" var="user" value="#{statisticsbean.userstatistics}"> <p:column styleclass="textcolumn"> <f:facet name="header"> <h:outputtext value="name" /> </f:facet> <h:outputtext value="#{user.firstname} #{user.lastname}"/> </p:column> ... <p:column styleclass="imagecolumn"> <f:facet name="header"> <h:outputtext value="luck barometer"/> </f:facet> <p:graphicimage value="#{user.thermochart}"/> </p:column> </p:datatable> </h:form>
can see doing wrong?
best not save image server, link in way. preferred solution have image generated on demand , streamed client servlet, link servlet (with parameters generate image of course) being injected in jsf instead of link pregenerated image file.
Comments
Post a Comment