I want execute one little jQuery code if my Primefaces view is loaded. This is the code for the jQuery function:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#myButton').click();
})
</script>
This is my hidden button for the referenced ID:
<p:commandButton id="myButton" actionListener="#{myController.myFunction()}" value="Bla bla" style="visibility: hidden;" ajax="false" />
This is how Primefaces includes jQuery:
<script type="text/javascript" src="/myapp/faces/javax.faces.resource/jquery/jquery.js?ln=primefaces&v=6.2"></script>
The jQuery code is generated, it's in the html source code, I can see it in the browser, but the click function is not executed, NetBeans breakpoint isn't activated (it's on the first line of the myFunction() ). What most important: I can't see any errors or relevant trace in the Chrome script console as well...
What am I missing here?
EDIT:
Chrome script console giving me this result if I enter "jQuery('myButton')":
I also edited my jQuery (I hope it's okay so...), because the id is generated, so it only included my referenced id:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("input[id*='myButton']").each(function (i, el) {
el.click();
});
})
</script>
Thank you.
EDIT2:
I changed my code as Melloware suggested, now my browser getting into infinte reload loop and I see following error in Chrome:
Edited jQuery:
<script type="text/javascript">
jQuery(document).ready(function(){
PF('myButton').jq.click();
})
</script>
Edited Button html:
<p:commandButton id="hiddenButton" widgetVar="myButton" actionListener="#{myController.myFunction()}" value="Bla bla" style="visibility: hidden;" ajax="false" />