Primefaces 5
I have following example:
<script>
function init () {
$("#myspan").doSomething;
}
</script>
<h:form rendered="some condition">
<span id="myspan" />
</h:form>
How to automaticaly call init() every time form will be updated ?
To rerun a script, simply re-render the tag that calls it. Assuming the form is re-rendered whenever it is "updated", this will do:
<script>
function init () {
$("#myspan").doSomething;
}
</script>
<h:form rendered="some condition">
<script type="text/javascript">init()</script>
<span id="myspan" />
</h:form>
Alternative solution would be to use <p:remoteCommand autoRun='true'>
<script>
function init () {
$("#myspan").doSomething;
}
</script>
<h:form rendered="some condition">
<span id="myspan" />
<p:remoteCommand autoRun="true" oncomplete="init();" />
</h:form>
In the solution of Ali the <script> tag is called earlier as the solution with <p:remoteComand>. The remoteCommand is called if output is already shown to user.