I have a simple JSF project (from the Core JavaServer Faces, 3rd Edition, Ch 4.), but the onclick doesn't appear to be executing the actual JavaScript file.
IDEA (14.1.4) seems happy with all the paths (such as <h:outputScript library="javascript" name="checkPassword.js"/>), and the project overall as far as I can see.
Also, I can hardcode an "alert()" into the onclick in the index.xhtml and that works.
This may not be an IDEA issue, but I'm confused why the JavaScript call isn't working.
Here's the JS file:
function checkPassword(form)
{
alert("inside js");
var password = form[form.id + ":password"].value;
var passwordConfirm = form[form.id + ":passwordConfirm"].value;
if(password == passwordConfirm)
form.submit();
else
alert("Password and password confirm fields don't match");
}
Here's the index.xhtml file that calls it:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>#{msgs.windowTitle}</title>
<h:outputStylesheet library="css" name="styles.css"/>
<h:outputScript library="javascript" name="checkPassword.js"/>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2" columnClasses="evenColumns, oddColumns">
#{msgs.namePrompt}
<h:inputText/>
#{msgs.passwordPrompt}
<h:inputSecret id="password"/>
#{msgs.confirmPasswordPrompt}
<h:inputSecret id="passwordConfirm"/>
</h:panelGrid>
<!--Execute JavaScript function on click of the button-->
<h:commandButton type="button" value="Submit Form" onclick="checkPassword(this.form)"/>
</h:form>
</h:body>
</html>
-----
Intellij is fine with the entire configuration. If I rename anything, it goes red right away. Yet, when I click the "Submit" button, absolutely nothing happens.
The project structure is shown on the attachment.
Any suggestions greatly appreciated.
Thanks,
- m