Plain javascript is executing at the client side.
Expressions like
"#{ControladorBk.getNroCasosPendientes()}"
- at server side.
So, you need to make a call to server to update "nroCasosPendientes
" and "nroRecorPendientes
"
You can achieve this by:
- Put values to hidden fields
- Update them by ajax call
- Get updated values in javascript
So, in html you need to add following code:
<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>
As you can see:
- Added two hidden fields for getting values from bean
- Added invisible button for performing ajax request
In <script>
you need to made some changes:
<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>
So, the changes are:
- Timer now will perform click on button, which will cause ajax request
- Hidden fields become updated by ajax
- After ajax success
notification()
will be called - In
notification()
values fornroCasosPendientes
andnroRecorPendientes
will be taken from hidden fields