Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF Page validation using Jquery not working

 
Soundarya Sethuraman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to validate my JSF page using JQuery. I tried a piece of code. But it did not work. The foll is my code.

<?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">
<h:head>
<link rel="stylesheet" href="style.css" />
<!-- Load jQuery and the validate plugin -->
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"/>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js" type="text/javascript"/>
<!-- jQuery Form Validation code -->
<script>
// When the browser is ready...
$(document).ready(function(){
// Setup form validation on the #loginform element
$("#loginform").click(function(){
var username = $('#userName').val();
var pwd = $('#passwrod').val();
if(username="")
{
$('#dis').slideDown().html('Please type user name');
return fasle;
}
if(pwd="")
{
$('#dis').slideDown().html('Please type password');
return fasle;
}
});
});
</script>
<title>Login Page</title>
</h:head>
<h:body>
<f:view>
<h:form id="loginform">
<h1>Login Page</h1>
<h:message for="userName"/></font>
<h:message for="password"/>
<table border="1" cellpadding="0" cellspacing="0" style="height: 134px">
<tr>
<td>UserName : </td>
<td><h:inputText id="userName" value="#{loginBean.userName}" /></td>
</tr>
<tr>
<td>Password :</td>
<td>
<h:inputSecret id="password" value="#{loginBean.password}" />
<h:link value="forgot passwrod" outcome="adduser" /></td>
</tr>
<tr>
<td>Role :</td>
<td>
<h:selectOneListbox value="#{loginBean.role}" style="height: 31px; width: 66px">
<f:selectItem id="chooserole" itemLabel="choose role"/>
<f:selectItem id="admin" itemLabel="admin" itemValue="admin" />
<f:selectItem id="user" itemLabel="user" itemValue="user" />
</h:selectOneListbox>
</td>
</tr>
</table>
<h:commandButton value="Clear" type="reset" actionListener="#{loginBean.clear}" immediate="true"/>
<h:commandButton value="Login" action="#{loginBean.findUser}" />
</h:form>
</f:view>
</h:body>
</html>

I have added the following dependency in my Pom:

<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.1.0-2</version>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery-validation</artifactId>
<version>1.11.1</version>
</dependency>

Please help me find out what the prob is.
 
Seven SpecialGems
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you considered using Primefaces? Primefaces brings jQuery to JSF's components:

http://www.primefaces.org/showcase/ui/home.jsf
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic