Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

client side validation in JSF

  Asked By: Carolina    Date: Oct 11    Category: Java    Views: 2700
  

Is there any solution for client-side validation in JSF ?
I heard Struts has some code generation (Java script) mechanism for this.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Murad Bashara     Answered On: Oct 11

you can use jsf  commonValidator



use this link http://shale.apache.org/shale-validator/index.html




Or take following steps . this one work fine for me


1. define a taglib like this on your project WEB_INF path with “corejsf-validator.taglib.xml” name and following content



<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://corejsf.com/validator</namespace>
<tag>
<tag-name>commonsValidator</tag-name>
<validator>
<validator-id>com.corejsf.validator.CommonsValidator</validator-id>
</validator>
</tag>
<tag>
<tag-name>validatorScript</tag-name>
<component>
<component-type>com.corejsf.validator.UIValidatorScript</component-type>
</component>
</tag>
</facelet-taglib>



2. on your web.xml add this context param

<context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>
/WEB-INF/corejsf-validator.taglib.xml
</param-value>
</context-param>






3. add this lines on your faces-config.xml file



<component>

<component-type>com.corejsf.validator.UIValidatorScript</component-type>

<component-class>com.corejsf.validator.UIValidatorScript</component-class>

</component>

<validator>

<validator-id>com.corejsf.validator.CommonsValidator</validator-id>

<validator-class>com.corejsf.validator.CommonsValidator</validator-class>

</validator>



4. and finally your page should be like this one

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core"
xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
xmlns:v="http://corejsf.com/validator">

<f:view>
<h:form id="userForm" onsubmit="return validateUserForm(this)">
<h:inputText value="#{user.username}" id="username" required="true"

</h:form>

<v:validatorScript functionName="validateUserForm"/>
</f:view>
</html>

 
Didn't find what you were looking for? Find more on client side validation in JSF Or get search suggestion and latest updates.




Tagged: