-
1. Re: How to stop a4j:poll if user is 'away'?
sergeysmirnov Mar 25, 2007 10:27 PM (in response to yeecn)How you did it with prototype? I mean if you have an already working code, you can use a4j:jsFunction to perform the JSF Ajax call from the code you already have.
-
2. Re: How to stop a4j:poll if user is 'away'?
yeecn Mar 25, 2007 11:14 PM (in response to yeecn)It is basically taggig a onmouseover event to , the event will set a hidden field (activeFlag).
Then there is a timer (initiated by setInterval()) for ajax form posting. The timer checks for the activeFlag before posting to the server, then clears the activeFlag.
The crux is in the posting back part - if I can control the a4j:poll posting back conditioned on a field that would be sufficient.
How about introduce a something like "stopIfInactive" attribute to a4j:poll:
<a4j:poll stopIfInactive=20000 ...
------------------------------------------------------
/* submit a form in ajax */
function invoke(form, event, container) {
var params = Form.serialize(form);
if (event != null) params = event + '&' + params;
new Ajax.Updater(container, form.action, method:'post', postBody:params});
}
function getTime() {
if ($("activeFlag").value == "1") {
invoke($("timerForm"), "getTime", $("sysTime"));
$("activeFlag").value = "0";
}
}
function init() {
setInterval('getTime()',5000);
document.getElementsByTagName("body")[0].onmouseover =
function(event) {
resetActiveFlag();
}
}
function resetActiveFlag() {
$("activeFlag").value = "1";
}
<body onLoad="javascript:init();">
... -
3. Re: How to stop a4j:poll if user is 'away'?
sergeysmirnov Mar 26, 2007 12:29 AM (in response to yeecn)<a4j:poll> has a onsubmit attribute. If the this function return false, the request will be canceled.
So, you can reuse your "activeFlag" . Let onsubmit return false if this flag equals 0 -
4. Re: How to stop a4j:poll if user is 'away'?
yeecn Mar 26, 2007 1:54 AM (in response to yeecn)Thanks. That's quite obvious, now that you pointed it out.
How about implementing an attribute in aj4:poll for this? I think this is a common enough requirements. The javascript to implement this is not trivial at all.
Regards -
5. Re: How to stop a4j:poll if user is 'away'?
sergeysmirnov Mar 26, 2007 10:45 AM (in response to yeecn)"yeecn@pd.jaring.my" wrote:
How about implementing an attribute in aj4:poll for this?
I am negative. This is an application specific behavior. -
6. Re: How to stop a4j:poll if user is 'away'?
logarr Oct 9, 2008 11:11 AM (in response to yeecn)"SergeySmirnov" wrote:
"yeecn@pd.jaring.my" wrote:
How about implementing an attribute in aj4:poll for this?
I am negative. This is an application specific behavior.
I disagree, controlling the polling that is controlled by the framework is a framework issue. Also, this is something that is pervasive across sites and applications. Making the developers remember to do this and do it consistently is tough. If the framework implements it, it gets very much easier, shortens development and test times and ensures that it happens in the first place. In my company, we have policies that deny auto-refresh for exactly the reason that we must time-out a session on USER inactivity. With no way to easily ensure that the coding in the client side is done correctly for every page, we say to turn refreshes off. If a framework like aj4 did this , we could re-think that position and give our users a better experience. -
7. Re: How to stop a4j:poll if user is 'away'?
ilya_shaikovsky Oct 13, 2008 11:50 AM (in response to yeecn)This is just your case. But lot of other users uses a4j:poll in order to prevent timeout while user is gone ;) So everyone need its own solution.