I’m trying to call JavaScript from bean. Script it work correct but when try to run it from bean get a error: Uncaught ReferenceError: funkcjaKolorujPredkosc is not defined
It is import to xml:
<h:head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="JavaScript/KolorSpeed.js" type="text/javascript"></script>
</h:head>
Script looks like that:
$(document).ready(
function funkcjaKolorujPredkosc(){
var allCells = $(".kolorSpeed > div");
$.each(allCells, function (index, child) {
var speedString = (child.textContent.replace("/","-")).toString();
var index = speedString.indexOf("-");
var actualSpeed = parseInt(speedString.substring(0, index));
var targetSpeed = parseInt(speedString.substring(index+1, speedString.length));
if (actualSpeed >= targetSpeed){
$(child).parent().css("color", "green");}
else{
$(child).parent().css("color", "red");
}
});
}
);
Calling from Bean:
public void idleMonitro() throws IOException, ParseException{
dataUpdate();
PrimeFaces.current().executeScript("funkcjaKolorujPredkosc();");
}
On Microsoft Edge it is working correct, there is a problem only on Firefox.
function funkcjaKolorujPredkosc() {};
$(document).ready(
function funkcjaKolorujPredkosc(){
all things the same, because you must pre-declared mechanism, definition without body structure
Karol is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2