I want to display some progress bar at the corner of the web page during AJAX call. I noticed that when Internet connection is slow user can't see that there is a AJAX call in progress. Is there any solution with core JSF?
Asked
Active
Viewed 1,435 times
0
-
There are events you can catch for the start and end of an ajax call. You know that do you? You can show anything in between those – Kukeltje Nov 01 '15 at 17:48
-
@Kukeltje can you show some example please? – Peter Penzov Nov 01 '15 at 17:58
-
Sorry no, I am lazy. Read the specs of the f:ajax tag http://docs.oracle.com/javaee/6/tutorial/doc/gkddf.html check the attributes and search further on google or stackoverflow. This is all so basic and easy to find via searchengines – Kukeltje Nov 01 '15 at 18:26
1 Answers
2
You could use onevent
attribute on f:ajax
.
<h:form>
<h:commandButton value="Test" action="#{ajaxTestBean.myAction}">
<f:ajax onevent="myFunc"/>
</h:commandButton>
</h:form>
<script type="text/javascript">
function myFunc(ajaxObj){
if('begin' == ajaxObj.status){
//Start or Show your Spinner
}else if('complete' == ajaxObj.status){
//Stop or Hide your Spinner
}
}
</script>
Here myFunc
will usually gets called 3 times.
- On Start of Ajax request [
status=='begin'
]. - On Complete of Ajax request [
status=='complete'
] - On Complete of Ajax request wit the
result [
status=='success'
]

Kishor Prakash
- 8,011
- 12
- 61
- 92
-
How I Can create progress bar like this? https://salt.bountysource.com/ – Peter Penzov Nov 02 '15 at 07:53
-
@PeterPenzov: By trying, banging your head, learning and asking detailed questions, not 'homework' ones. And the basic answer is already in this duplicate: http://stackoverflow.com/questions/11350769/ajax-call-in-jsf-2-0-myfaces-the-onevent-javascipt-function-in-the-ajax-tag-g – Kukeltje Nov 02 '15 at 08:30
-
-
@BalusC : Oh yes its not there. I'll remove it from answer. Thanks. – Kishor Prakash Nov 02 '15 at 09:23