File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes JSF Page validation using Jquery not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Page validation using Jquery not working" Watch "JSF Page validation using Jquery not working" New topic
Author

JSF Page validation using Jquery not working

Soundarya Sethuraman
Greenhorn

Joined: Apr 08, 2014
Posts: 1
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

Joined: Apr 08, 2014
Posts: 3
Have you considered using Primefaces? Primefaces brings jQuery to JSF's components:

http://www.primefaces.org/showcase/ui/home.jsf


7SpecialGeMs
 
jQuery in Action, 2nd edition
 
subject: JSF Page validation using Jquery not working
 
Similar Threads
Spring MVC - Question
JSF - Missing source code using templating and composition
CSS in JSF
unable to load faces-config.xml
binding xhtml and bean not working and the problem is : javax.el.PropertyNotFoundException