Description:
When using Primefaces html page is rendered by Servlet. Sometimes Servlet generates only html tags, but sometimes generates javascript.
Case 1
XHTML:
<h:outputText id="outputId" value="Hello!!!" />
Generated:
<span id="outputId">Hello!!!</span>
In this case it is very easy to add addtional callback using jQuery script. Beacouse all html elements are already generated.
Case 2:
XHTML:
<p:schedule id="bigCalendarId" value="#{csController.lazyEventModel} view="month" />
This example shows that not always pure html is generated. In this case javascipt is generated:
<script id="formId:bigCalendarId_s" type="text/javascript">$(function(){PrimeFaces.cw('Schedule','widget_formId_bigCalendarId',{id:'formId:bigCalendarId',defaultView:'month',offset:3600000,header:{left:'prev,next today',center:'title',right:'month,agendaWeek,agendaDay'}},'schedule');});</script>
So Primefaces use some script to finish initialization. This function is called when DOM tree is built.
Question:
Primafaces uses script to build view, but I would like to add some calbacks to generated content. Problem is that my script has to be executed after javascript generated by Primefaces is finished. How to achieve that? How to execute my script after Primefaces?
There are 2 ways that work for me, when I want to execute a JS function after page load in Primefaces:
jQuery(document).ready(function () {
jQuery(document).ready(function () {
// twice in document.ready to execute after Primefaces callbacks
myInitialisationFunction();
});
});<p:remoteCommand oncomplete=" myInitialisationFunction(); " autoRun="true"/>If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With