html - Dialog content does not get updated -
i have searched hours, , i've found stackoverflow questions related it, not find solution. have primefaces dialog displays content of log file. dialog shown when pressing button. problem once dialog displayed, content never updated. is, #{pvtrunner.pvtlog} method never called. how can make dialog call method every time displayed, not first time?
<h:head> </h:head> <h:body> <p:dialog id="logdialog" header="pvt log" widgetvar="dlg" height="400" width="600" dynamic="true"> <h:outputtext id="logdialogcontnet" value="#{pvtrunner.pvtlog}" escape="false"/> </p:dialog> <h:form> <p:panelgrid id="mainpanelgrid" columns="1" styleclass="panelgridborder panelgridcenter"> .... <p:commandbutton id="showlog" value="show log" onclick="dlg.show()" type="button" update=":logdialogcontnet"/> </p:panelgrid> </h:form> </h:body> this java method should update dialog content:
public string getpvtlog() { string result = ""; try { file logfile = new file(instanceroot + "\\config\\processverification.log"); inputstream fis = new fileinputstream(logfile); result = readstream(fis); } catch (ioexception e) { log.severe(e.getmessage()); } return result; } thanks
first things first, stop doing business logic in getter. should returning property. below 1 approach use. make sure check link.
modify getpvtlog()
public string getpvtlog() { return result; } then define method used actionlistener in <p:commandbutton>to update result. example:
public void click() { try { file logfile = new file(instanceroot + "\\config\\processverification.log"); inputstream fis = new fileinputstream(logfile); result = readstream(fis); } catch (ioexception e) { log.severe(e.getmessage()); } return result; } change method name see fit. quick example.
now remove type="button" , instead of onclick change oncomplete. onclick executed before ajax request, want <p:dialog> pop after ajax request. believe main issue way. add actionlistener in <p:commandbutton>.
<p:commandbutton id="showlog" actionlistener="#{pvtrunner.click()}" value="show log" oncomplete="dlg.show()" update=":logdialogcontnet"/> sample
<p:dialog id="logdialog" header="pvt log" widgetvar="dlg" height="400" width="600" dynamic="true"> <h:outputtext id="logdialogcontnet" value="#{pvtrunner.pvtlog}" escape="false"/> </p:dialog> <h:form> <p:panelgrid id="mainpanelgrid" columns="1" styleclass="panelgridborder panelgridcenter"> <p:commandbutton id="showlog" actionlistener="#{pvtrunner.click()}" value="show log" oncomplete="dlg.show()" update=":logdialogcontnet"/> </p:panelgrid> </h:form>
Comments
Post a Comment