To the point, you need to understand that JSF merely produces HTML code and that JS is part of HTML. So all you need to do is to write JSF/EL code accordingly that it produces valid HTML/JS code. Indeed, using EL to inline bean properties in the generated JavaScript code like as in your attempt is one of the right ways.
Assuming that this is indeed the real code, you however made some syntax mistakes. The onClick
attribute is invalid. It must be in all lowercase. Otherwise JSF simply won't render the attribute at all.
<h:commandLink value="link" onclick="showNoQueryPrompt(#{enquiry.noQuery})" />
JavaScript has no notion of strong typing. The Boolean
type in function argument is invalid. Remove it. Otherwise you will face a nice JS syntax error (in browser's JS console).
function showNoQueryPrompt(showPrompt) {
if (showPrompt) {
alert('No query');
}
}
Note that I expect that you understand that this runs before commandlink's own action
is been invoked (you should now have understood; JSF generates HTML; rightclick page in browser and View Source to see it yourself). But you didn't cover that in your concrete question (even more, you didn't describe the concrete problem with the given code in the question at all), so I can't give an detailed answer on that.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…