Javascript 如何在<;中刷新脚本;h:头>;在JFS中?
早上好 我在Google Chrome中使用Web API通知,问题是:我的xhtml页面头部有一个脚本,用于检索值从一个数据库到一个托管bean,这个过程必须每10秒在一个计时器(间隔)上完成,第一次它工作正常,但有时不返回以下值在数据库中,而是在第一次恢复时继续显示值再次从数据库中的托管bean开始恢复我的代码如下,希望对您有所帮助Javascript 如何在<;中刷新脚本;h:头>;在JFS中?,javascript,jquery,jsf,web-notifications,Javascript,Jquery,Jsf,Web Notifications,早上好 我在Google Chrome中使用Web API通知,问题是:我的xhtml页面头部有一个脚本,用于检索值从一个数据库到一个托管bean,这个过程必须每10秒在一个计时器(间隔)上完成,第一次它工作正常,但有时不返回以下值在数据库中,而是在第一次恢复时继续显示值再次从数据库中的托管bean开始恢复我的代码如下,希望对您有所帮助 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.su
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ace="http://www.icefaces.org/icefaces/components">
<h:head>
<script>
if (!window.webkitNotifications)
{
alert('Lo sentimos, su navegador no soporta notificación de escritorio. Trabaje con Google Chrome.');
}
function RequestPermission (callback)
{
window.webkitNotifications.requestPermission(callback);
}
function getNroCasosPendientes()
{
var nroCasosPendientes = '#{ControladorBk.getNroCasosPendientes()}';
return nroCasosPendientes;
}
function getNroRecordatoriosPendientes()
{
var nroRecorPendientes = '#{ControladorBk.getNroRecordatoriosPendientes()}';
return nroRecorPendientes;
}
function abrirVentana(url)
{
var height = screen.availHeight-30;
var width = screen.availWidth-10;
var left = 0;
var top = 0;
settings = 'fullscreen=no,resizable=yes,location=no,toolbar=no,menubar=no';
settings = settings + ',status=no,directories=no,scrollbars=yes';
settings = settings + ',width=' + width +',height=' + height;
settings = settings + ',top=' + top +',left=' + left;
settings = settings + ',charset=iso-8859-1';
var win = window.open(url, '', settings);
win.outerHeight = screen.availHeight;
win.outerWidth = screen.availWidth;
win.resizeTo(screen.availWidth, screen.availHeight);
if (!win.focus)
{
win.focus();
}
return win;
}
function notification ()
{
if (window.webkitNotifications.checkPermission() > 0)
{
RequestPermission(notification);
}
var icon = 'http://entidades.com/images/img999.png';
var title = 'AVISO';
var nroCasosPendientes = getNroCasosPendientes();
var nroRecorPendientes = getNroRecordatoriosPendientes();
if(nroCasosPendientes != '0' || nroRecorPendientes != '0')
{
var body = 'Tienes '+nroCasosPendientes+' Casos y '+nroRecorPendientes + ' Recordatorios pendientes.';
var popup = window.webkitNotifications.createNotification(icon, title, body);
popup.show();
setTimeout(function()
{
popup.cancel();
}, '5000');
popup.onclick = function()
{
abrirVentana('http://localhost:8080/Proyect/faces/Page.xhtml');
};
}
}
var timer = setInterval(function()
{
notification();
}, 10000);
</script>
</h:head>
如果(!window.webkit通知)
{
警报('Lo sentimos,su navegador no soporta notificación de escritorio.Trabaje con Google Chrome');
}
函数RequestPermission(回调)
{
window.webkitNotifications.requestPermission(回调);
}
函数getnRocasoSpendients()
{
var nrocasospendentes='#{controladrobk.getnrocasospendentes()}';
返回nRocasoSpendentes;
}
函数getNroRecordatoriosPendientes()
{
var nRoreCorpendentes='#{controladrobk.getnRoreCortoriosPendentes()}';
返回nR独立公司;
}
函数abrirVentana(url)
{
变量高度=屏幕可用高度-30;
变量宽度=screen.availWidth-10;
左向量=0;
var-top=0;
设置='全屏=否,可调整大小=是,位置=否,工具栏=否,菜单栏=否';
设置=设置+',状态=否,目录=否,滚动条=是';
设置=设置+',宽度='+宽度+',高度='+高度;
设置=设置+',顶部='+顶部+',左侧='+左侧;
设置=设置+',字符集=iso-8859-1';
var win=window.open(url',设置);
win.outerHeight=screen.availHeight;
win.outerWidth=screen.availWidth;
win.resizeTo(screen.availWidth,screen.availHeight);
如果(!win.focus)
{
win.focus();
}
回归胜利;
}
函数通知()
{
if(window.webkitNotifications.checkPermission()>0)
{
请求许可(通知);
}
var图标http://entidades.com/images/img999.png';
var title='AVISO';
var nrocasospendentes=getnrocasospendentes();
var nRoreCorpendentes=getnRoreCortoriosPendentes();
如果(nRocasoSpendients!=“0”| | nRorecorependents!=“0”)
{
var body='Tienes'+nroCasosPendientes+'Casos y'+nRoreCorpendentes+'Recordatorios pendentes';
var popup=window.webkitNotifications.createNotification(图标、标题、正文);
popup.show();
setTimeout(函数()
{
popup.cancel();
}, '5000');
popup.onclick=函数()
{
阿布里文塔纳酒店http://localhost:8080/Proyect/faces/Page.xhtml');
};
}
}
var timer=setInterval(函数()
{
通知();
}, 10000);
普通javascript正在客户端执行
表达方式如
“#{controladrobk.getnrocasospendentes()}”
-在服务器端
所以,您需要调用服务器来更新“nrocasospendentes
”和“nrocorpendentes
”
您可以通过以下方式实现此目的:
因此,在html中,您需要添加以下代码:
<h:form>
<h:inputHidden id="hiddenCasos"
value="#{ControladorBk.getNroCasosPendientes()}"/>
<h:inputHidden id="hiddenRecordatorios"
value="#{ControladorBk.getNroRecordatoriosPendientes()}"/>
<h:commandLink id="btnUpdate"
style="display: none">
<f:ajax render="hiddenCasos hiddenRecordatorios"
onevent="performNotification"/>
</h:commandLink>
</h:form>
如你所见:
在
中,您需要进行一些更改:
<script>
//your code
//add this...
function updateBean() {
document.getElementById("btnUpdate").click();
}
//...and this
function performNotification(data) {
if(data.status === 'success') {
notification();
}
}
//...change this
function notification() {
//your code
//get values from hidden fields
var nroCasosPendientes = document.getElementById("hiddenCasos").value;
var nroRecorPendientes = document.getElementById("hiddenRecordatorios").value;
}
//...and change this
var timer = setInterval(function{
updateBean();
}, 10000);
</script>
//你的代码
//加上这个。。。
函数updateBean(){
document.getElementById(“btnUpdate”)。单击();
}
//…还有这个
功能执行通知(数据){
如果(data.status==“成功”){
通知();
}
}
//…改变这个
函数通知(){
//你的代码
//从隐藏字段中获取值
var nrocasospendentes=document.getElementById(“hiddenCasos”).value;
var nRoreCorpendentes=document.getElementById(“hiddenRecordatorios”).value;
}
//…然后改变这个
var定时器=设置间隔(功能{
updateBean();
}, 10000);
因此,这些变化是:
通知()
notification()
中,为nRocasoSpendients
和
nOreCorpendentials
将从隐藏字段中获取