I have this code:
<div id="visibleButtons">
<p:commandButton id="hint" action="#{tutorSession.hintRequest}" value="Hint Please" update="@parent" oncomplete="playNextHint(#{tutorSession.giveWarning});">
</p:commandButton>
<p:commandButton id="newType" action="#{tutorSession.newPathRequest}" value="Something Else" update="@parent" oncomplete="playNextHint(#{tutorSession.giveWarning});">
</p:commandButton>
#{tutorSession.giveWarning}<!-- I will remove this line once the buttons are working -->
</div>
and what is happening is that the javascript function playNextHint is executing with the value of giveWarning from the last call, rather than the current one. I checked that the server is returning the right value; it is. In fact, I added that little bit of text output at the bottom to verify that the right value is being returned, and it always displays the way I expect, but the javascript still uses the old value.
Any thoughts on what might be happening?
The javascript method, in case it is relevant:
function playNextHint(giveWarning){
alert(giveWarning);
}
Thank you in advance.
Edit: I found a work-around by using a hidden field with the value, and then getting the value of that field in the javascript, but that is messy and there has to be a better way, as I will be doing a lot of this sort of thing for this web app.
Edit 2: Sorry, I left in some code for demonstration purposes that seems to have confused people. First, I do NOT want to display giveWarning. That is just there so I could see that it was getting the right value. I left it in so people could see where the right value does show up, as opposed to where it does not.
Edit 3: What I want to do when the button is pressed is compute the new value of giveWarning on the server (that part works) and then send it to a javascript function to do logic based on it (the alert is a placeholder and for testing). The problem is that the value the javascript function gets always seems to be one click behind what it should be, even though when I just send the value tot he screen (the last line in the div) it displays what it should. Sorry for all the edits; like I said, it's my first time posting.