先看下面的 JSF 页面:
<%...@ page language="java" pageEncoding="UTF-8"%>
<%...@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%...@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html>
<head>
<title>My JSF 'login.jsp' starting page</title>
<script type="text/javascript">...
function isEmpty() ...{
var username = document.getElementById("formLogin:txtUsername").value;
var password = document.getElementById("formLogin:txtPassword").value;
if(username == "") ...{
alert("给老子输用户名!");
document.getElementById("formLogin:txtUsername").focus();
return false;
}
if(password == "") ...{
alert("不输密码你登录个铲铲!");
document.getElementById("formLogin:txtPassword").focus();
return false;
}
}
</script>
</head>
<body>
<center>
<f:view>
<h:form id="formLogin">
<div id="input">
<h:outputLabel value="用户名:" />
<h:inputText value="#{LoginManager.username}" id="txtUsername"
styleClass="formText" />
<br>
<h:outputLabel value="?密码:" />
<h:inputSecret value="#{LoginManager.password}" id="txtPassword"
styleClass="formText" />
</div>
<div id="submit">
<h:commandButton value="提交" action="#{LoginManager.check}"
onclick="return isEmpty();" styleClass="formButton" />
<h:commandButton value="重置" type="button"
onclick="javascript:document.getElementById('formLogin').reset();
document.getElementById('formLogin:txtUsername').focus();"
styleClass="formButton" />
</div>
</h:form>
</f:view>
</center>
</body>
</html>