Reputation: 2406
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 ?
Upvotes: 2
Views: 7000
Reputation: 2406
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.
Upvotes: 5
Reputation: 3856
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>
Upvotes: 6