As an exercise, I'm trying to create a simple page where you have two stock quotation, set to starting values 100 and 200. The methods updateValues() modify the quotation value by +/-1% and the displayAction() method return the String "<name of the quotation> = <value of the quotation>". Anyway, if I click the button "Refresh Values" the two quotation doesn't change. Wat I'm doingo wrong?
Here's my index.jsp:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<jsp:useBean id="enel" class="it.unitn.studenti.porcelli.leonardo.esamefebbraio2022.businessobject.Enel" scope="application"></jsp:useBean>
<jsp:useBean id="webuild" class="it.unitn.studenti.porcelli.leonardo.esamefebbraio2022.businessobject.WeBuild" scope="application"></jsp:useBean>
<!DOCTYPE html>
<html>
<head>
<title>PWEB Banking</title>
</head>
<body>
<script>
function startIsClicked(){
document.querySelector("#start_button").disabled = true;
document.querySelector("#stop_button").disabled = false;
}
function stopIsClicked(){
document.querySelector("#start_button").disabled = false;
document.querySelector("#stop_button").disabled = true;
}
function refreshValues(enel, webuild){
const xhttp = new XMLHttpRequest();
xhttp.onload = function (){
const newEnelValue = <%enel.updateValue();%>;
document.getElementById("Enel").innerHTML = enel.displayAction();
const newWebuildValue = <%webuild.updateValue();%>;
document.getElementById("Webuild").innerHTML = webuild.displayAction();
}
xhttp.open("GET", "index.jsp", true);
xhttp.send();
}
</script>
<div id="buttons">
<button id="start_button" type="button" name="start" onclick="startIsClicked()">Start</button>
<button id="stop_button" type="button" name="start" onclick="stopIsClicked()" disabled>Stop</button>
</div>
<div id="Enel">
<%=enel.displayAction()%>
</div>
<div id="Webuild">
<%=webuild.displayAction()%>
</div>
<button type="button" onclick="refreshValues(<%=enel%>, <%=webuild%>)">Refresh Values</button>
<br/>
</body>
</html>