Javascript破坏了基于PrimeFaces的页面中的导航
我使用了一些第三方连接监控代码(由Denis Radin编写),它与我的页面上的导航元素进行了交互,我根本不理解。我希望有人能解释一些可能的原因,这样我就能更好地纠正这个问题 当Javascript代码就位时,我有一个PrimeFacesCommandButton元素,它开始间歇性地失败;有时它会把我带到我想要的页面,有时它什么也不做Javascript破坏了基于PrimeFaces的页面中的导航,javascript,ajax,jsf,primefaces,Javascript,Ajax,Jsf,Primefaces,我使用了一些第三方连接监控代码(由Denis Radin编写),它与我的页面上的导航元素进行了交互,我根本不理解。我希望有人能解释一些可能的原因,这样我就能更好地纠正这个问题 当Javascript代码就位时,我有一个PrimeFacesCommandButton元素,它开始间歇性地失败;有时它会把我带到我想要的页面,有时它什么也不做 <p:commandButton icon="icon-back" value="#{appMsgs['button
<p:commandButton
icon="icon-back"
value="#{appMsgs['button.back.to.inbox']}"
rendered="#{viewBean.back}"
actionListener="#{controllerBean.selectState}"
update=":frmMain:mainContent" />
旧的非jQuery代码:
(函数(w){
w、 internetConnection=w.internetConnection |{};
w、 internetConnection.addEvent=函数(对象、类型、回调){
如果(窗口附件){
obj.attachEvent('on'+类型,回调);
}否则{
obj.addEventListener(类型,回调);
}
};
var xmlhttp=new XMLHttpRequest();
w、 internetConnection.isXMLHttp=function(){
在xmlhttp中返回“withCredentials”;
};
w、 internetConnection.isXDomain=函数(){
返回XDomainRequest的类型!=“未定义”;
};
//对于IE,我们使用XDomainRequest,有时它使用一些不同的逻辑,所以为此添加了decorator
w、 internetConnection.XDomainLogic={
init:function(){
xmlhttp=新的XDomainRequest();
xmlhttp.onerror=函数(){
xmlhttp.status=404;
w、 internetConnection.processXmlhttpStatus();
};
xmlhttp.ontimeout=函数(){
xmlhttp.status=404;
w、 internetConnection.processXmlhttpStatus();
};
},
OnInternetSyncStatus:函数(){
试一试{
xmlhttp.status=200;
w、 internetConnection.processXmlhttpStatus();
}捕捉(错误){
w、 internetConnection.fireHandlerDependOnStatus(错误);
w、 在线=假;
}
},
checkConnectionWithRequest:函数(异步){
xmlhttp.onload=w.internetConnection.logic.onInternetSyncStatus;
var url=w.onLineCheckURL();
open(“GET”,url);
xmlhttp.send();
}
};
//另一个装饰案例是XMLHttpRequest
w、 internetConnection.XMLHttpLogic={
init:function(){
},
OnInternetSyncStatus:函数(){
if(xmlhttp.readyState==4){
试一试{
w、 internetConnection.processXmlhttpStatus();
}捕捉(错误){
w、 internetConnection.fireHandlerDependOnStatus(错误);
w、 在线=假;
}
}
},
checkConnectionWithRequest:函数(异步){
如果(异步){
xmlhttp.onreadystatechange=w.internetConnection.logic.onInternetSyncStatus;
}否则{
xmlhttp.onreadystatechange=未定义;
}
var url=w.onLineCheckURL();
open(“HEAD”,url,异步);
xmlhttp.send();
如果(异步===false){
w、 internetConnection.processXmlhttpStatus();
返回w.onLine;
}
}
};
if(w.internetConnection.isXDomain()){
w、 internetConnection.logic=w.internetConnection.XDomainLogic;
}否则{
w、 internetConnection.logic=w.internetConnection.XMLHttpLogic;
}
w、 internetConnection.logic.init();
w、 internetConnection.processXmlhttpStatus=函数(){
var tempOnLine=w.internetConnection.verifyStatus(xmlhttp.status);
w、 互联网连接。fireHandlerDependOnStatus(tempOnLine);
w、 在线=临时在线;
};
w、 internetConnection.verifyStatus=功能(状态){
返回(状态>=200&&status<300 | | status==304);
};
w、 internetConnection.fireHandlerDependOnStatus=函数(newStatus){
if(newStatus==true&&w.onLineHandler!==undefined&&w.onLine!==true | | w.internetConnection.handlerfied==false)){
w、 onLineHandler();
}
if(newStatus==false&&w.offLineHandler!==undefined&&w.onLine!==false | | w.internetConnection.handlerfied==false)){
w、 离线处理程序();
}
w、 internetConnection.handlerFired=true;
};
w、 internetConnection.startCheck=函数(){
setInterval(“window.internetConnection.logic.checkConnectionWithRequest(true)”,w.onLineCheckTimeout);
};
w、 internetConnection.stopCheck=函数(){
clearInterval(“window.internetConnection.logic.checkConnectionWithRequest(true)”,w.onLineCheckTimeout);
};
w、 checkOnLine=函数(){
w、 internetConnection.logic.checkConnectionWithRequest(false);
};
w、 onLineCheckURL=函数(){
返回window.location.href;
};
w、 onLineCheckTimeout=5000;
w、 在线检查();
w、 internetConnection.startCheck();
w、 internetConnection.handlerFired=false;
<p:dataTable
id="widgets"
value="#{cc.attrs.widgetList}"
var="widget"
widgetVar="widgetTable"
rowKey="#{widget.widgetId}"
selectionMode="single"
<p:ajax
event="rowSelect"
listener="#{controllerBean.handleWidget}"
update=":frmMain:mainContent"
onstart="widgetTable.clearSelection()"
process=":frmMain:txtInputTimeElapsed :frmMain:txtInputTimeRemaining :frmMain:mainContent" />
...
</p:dataTable>
(function(e){
e.fn.checknet=function(config){
function connectionLost(){
wdgNoConnection.show();
if(#{bizSimViewBean.started}) {
pauseTimer();
}
}
function connectionExtablished(){
wdgNoConnection.hide();
if(#{bizSimViewBean.started}) {
startTimer();
}
}
function checkConnection(url){
e.ajax({
url:url,
cache:false,
success:function(){
if (!window.checknet.conIsActive) {
window.checknet.statusChange = true;
}
window.checknet.conIsActive=true
},
error:function(){
if (window.checknet.conIsActive) {
window.checknet.statusChange = true;
}
window.checknet.conIsActive=false
},
complete:function(){
if (window.checknet.statusChange) {
if(window.checknet.conIsActive){
connectionExtablished()
}
else{
connectionLost()
}
window.checknet.statusChange = false;
}
}
})
setTimeout(
function(){checkConnection(window.checknet.config.checkURL)},
window.checknet.config.checkInterval
)
}
if(typeof t==="undefined"){
var t={}
}
if(typeof config.checkInterval==="undefined"){
t.checkInterval=5e3
}
if(typeof config.checkURL==="undefined"){
t.checkURL=window.location
}
else if(config.checkURL.indexOf("http")===-1){
t.checkURL="http://"+t.checkURL
}
checkConnection(config.checkURL)
}
})(jQuery);
$(document).ready(function(){
window.checknet={};
window.checknet.config={};
$.fn.checknet(window.checknet.config);
});
(function (w){
w.internetConnection = w.internetConnection || {};
w.internetConnection.addEvent = function(obj, type, callback){
if (window.attachEvent){
obj.attachEvent('on' + type, callback);
} else {
obj.addEventListener(type, callback);
}
};
var xmlhttp = new XMLHttpRequest();
w.internetConnection.isXMLHttp = function(){
return "withCredentials" in xmlhttp;
};
w.internetConnection.isXDomain = function(){
return typeof XDomainRequest != "undefined";
};
//For IE we use XDomainRequest and sometimes it uses a bit different logic, so adding decorator for this
w.internetConnection.XDomainLogic = {
init: function(){
xmlhttp = new XDomainRequest();
xmlhttp.onerror = function(){
xmlhttp.status = 404;
w.internetConnection.processXmlhttpStatus();
};
xmlhttp.ontimeout = function(){
xmlhttp.status = 404;
w.internetConnection.processXmlhttpStatus();
};
},
onInternetAsyncStatus: function(){
try {
xmlhttp.status = 200;
w.internetConnection.processXmlhttpStatus();
} catch(err){
w.internetConnection.fireHandlerDependOnStatus(false);
w.onLine = false;
}
},
checkConnectionWithRequest: function(async){
xmlhttp.onload = w.internetConnection.logic.onInternetAsyncStatus;
var url = w.onLineCheckURL();
xmlhttp.open("GET", url);
xmlhttp.send();
}
};
//Another case for decoration is XMLHttpRequest
w.internetConnection.XMLHttpLogic = {
init: function(){
},
onInternetAsyncStatus: function(){
if (xmlhttp.readyState === 4){
try {
w.internetConnection.processXmlhttpStatus();
} catch(err){
w.internetConnection.fireHandlerDependOnStatus(false);
w.onLine = false;
}
}
},
checkConnectionWithRequest: function(async){
if (async) {
xmlhttp.onreadystatechange = w.internetConnection.logic.onInternetAsyncStatus;
} else {
xmlhttp.onreadystatechange = undefined;
}
var url = w.onLineCheckURL();
xmlhttp.open("HEAD", url, async);
xmlhttp.send();
if (async === false) {
w.internetConnection.processXmlhttpStatus();
return w.onLine;
}
}
};
if (w.internetConnection.isXDomain()) {
w.internetConnection.logic = w.internetConnection.XDomainLogic;
} else {
w.internetConnection.logic = w.internetConnection.XMLHttpLogic;
}
w.internetConnection.logic.init();
w.internetConnection.processXmlhttpStatus = function(){
var tempOnLine = w.internetConnection.verifyStatus(xmlhttp.status);
w.internetConnection.fireHandlerDependOnStatus(tempOnLine);
w.onLine = tempOnLine;
};
w.internetConnection.verifyStatus = function(status){
return ( status >= 200 && status < 300 || status === 304 );
};
w.internetConnection.fireHandlerDependOnStatus = function (newStatus){
if (newStatus === true && w.onLineHandler !== undefined && (w.onLine !== true || w.internetConnection.handlerFired === false)){
w.onLineHandler();
}
if (newStatus === false && w.offLineHandler !== undefined && (w.onLine !== false || w.internetConnection.handlerFired === false)){
w.offLineHandler();
}
w.internetConnection.handlerFired = true;
};
w.internetConnection.startCheck = function (){
setInterval("window.internetConnection.logic.checkConnectionWithRequest(true)",w.onLineCheckTimeout);
};
w.internetConnection.stopCheck = function (){
clearInterval("window.internetConnection.logic.checkConnectionWithRequest(true)",w.onLineCheckTimeout);
};
w.checkOnLine = function(){
w.internetConnection.logic.checkConnectionWithRequest(false);
};
w.onLineCheckURL = function(){
return window.location.href;
};
w.onLineCheckTimeout = 5000;
w.checkOnLine();
w.internetConnection.startCheck();
w.internetConnection.handlerFired = false;
w.internetConnection.addEvent(w, 'load', function(){
w.internetConnection.fireHandlerDependOnStatus(w.onLine);
});
w.internetConnection.addEvent(w, 'online', function(){
window.internetConnection.logic.checkConnectionWithRequest(true);
});
w.internetConnection.addEvent(w, 'offline', function(){
window.internetConnection.logic.checkConnectionWithRequest(true);
});
})(window);
var offline = false;
window.onLineHandler = function(){
if (offline) {
wdgNoConnection.hide();
if(#{bizSimViewBean.started}) {
startTimer();
}
}
offline = false;
};
window.offLineHandler = function(){
if (!offline) {
wdgNoConnection.show();
if(#{bizSimViewBean.started}) {
pauseTimer();
}
}
offline = true;
};