CommandButton不会在JSF中调用javascript

时间:2014-06-23 13:11:25

标签: javascript jsf

声明和调用在这里:

<?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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>#{msgs.windowTitle}</title>
  <h:outputScript library="javascript" name="Resources/js/checkPassword.js" />
</head>

<body>
<h3>#{msgs.Entrance}</h3><br/><br/><br/>
<h:form>

<h:panelGrid columns="2" columnsClasses="evenColumns, oddColumns">

#{msgs.namePrompt}
<h:inputText/>

#{msgs.PasswordPrompt}
<h:inputSecret id="password" />

#{msgs.ConfirmPasswordPrompt}
<h:inputSecret id="passwordConfirm"/>

</h:panelGrid>

<h:commandButton type="button" value="Submit" onclick="checkPassword()" />
    </h:form>
    </body>

</html>

checkpassdword.js

 function checkPassword(){
        alert("here it is");
        var password = form[form.id+":passwordConfirm"].value;

        var passwordConfirm = form[form.id+":password"].value;
        if(password==passwordConfirm){
            form.submit();
        }
        else{
            alert("Wrong");
        } 

    }

位于WebContent/Resources/js

当我用put编写时,单击按钮,没有任何反应。

在资源管理器中,错误在控制台中

<script src="RES_NOT_FOUND" type="text/javascript"></script>

我该如何解决这个问题?我试图输入src,webinf,meta inf并试图声明src不是名字但没有发生任何事情。

错误未识别的checkPassword。

1 个答案:

答案 0 :(得分:0)

替换

<h:outputScript library="javascript" name="Resources/js/checkPassword.js" />

 <h:outputScript name="js/checkPassword.js"/>

并将您的WebContent中的Resources文件夹重命名为resources

并查看以下主题What is the JSF resource library for and how should it be used?