I am using this code in my .xhtml page
In head tag, i am using for refresh purpose,
<script type="text/javascript">
alert("hi");
setInterval(function() {
document.getElementById('myForm:btnLoadData').submit();
alert("Hello");
}, 3000);
</script>
and inside ui:define tag i am writing this code.
<h:panelGroup id="divData" layout="block">
//my jsf code..................
</h:panelGroup>
<h:form id="myForm">
<h:commandButton id="btnLoadData" value="Hidden" style="display:none">
<f:ajax execute="@form" render=":divData" />
</h:commandButton>
</h:form>
After all this I am not getting any error, but the hidden button is not working as desired in script. Even I cant see the alert("Hello").
Update: I can see the first alert("hi") but not alert("Hello")
I am newbie in jsf. I have to implement polling type thing or auto refresh. I also tried this example. But its not working.
Problem 2 I dont know that much jsf. At some places I am using normal HTML tags. I dont know why URL is not showing the page name. Its always like host/myProjectName. I am expecting host/projectName/Login.xhtml or host/projectName/SomeOtherPage.xhtml Even browser back button or reload for that particular page not works. It reloads from first page of my project i-e Login page. Are both problems interrelated. How can I handle this.
Somebody please help me with the problem.
来源:https://stackoverflow.com/questions/26151422/auto-refresh-in-jsf-using-ajax