YAV tags

Overview

YAV-tags is a JSP library tag for YAV Javascript validation tool

YAV is a javascript library which provides web forms validation via Javascript.

YAV-tags makes easier to use this library from JSP pages and adds server-side validation.

Features

Download

YAV-tags 1.0 beta is out!

You can download it at sourceforge YAV-tags project download page.

This release implements all YAV rules on the server side having no known critical bugs. During beta stage we expect to discover and fix any bug, in order to release a production-ready version.

In case you experiment any problem, please report it at the YAV-tags bug tracking system.

Quick start

  1. Add yavtags.jar to your application's classpath (usually, WEB-INF/lib folder).
  2. Configure the filter in your web application descriptor (web.xml) like that:
    <filter>
       <filter-name>YavTags</filter-name>
       <filter-class>net.sf.yavtags.YavFilter</filter-class>
    </filter>
    <filter-mapping>
       <filter-name>YavTags</filter-name>
       <url-pattern>*.do</url-pattern>
    </filter-mapping>
    replacing *.do to suit your needs.
  3. Link Yav javascript code adding this configuration into your web.xml:
    <servlet>
       <servlet-name>YavServlet</servlet-name>
       <servlet-class>net.sf.yavtags.web.YavServlet</servlet-class>
    </servlet>
    <servlet-mapping>
       <servlet-name>YavServlet</servlet-name>
       <url-pattern>/js/yav.js</url-pattern>
    </servlet-mapping>
  4. See advanced configuration for further details, specially if you need multipart uploads support.

Usage

Basic usage

  1. Add tag library declaration at the top of your JSP (it could be in an include fragment or JSP prelude):
    <%@taglib prefix="yav" uri="http://net.sf.yavtags"%>
  2. Surround HTML form with validate tag: <yav:validate>
       <form action="xxx.do">
          ...
       </form>
    </yav:validate>
  3. Add a rule tag after every field that you want to validate:
    Username: <input name="username" type="text" />
    <yav:rule value="username|required" />
    Age: <input name="age" type="text" />
    <yav:rule value="age|integer" />
    Rule syntax is YAV's one.

Help tips

You could add a tip for a field like that:

Username: <input name="username" type="text" />
<yav:help for="username" message="Provide a short username" />

Custom masks

Custom masks are defined this way:

Birthday: <input name="birthdate" type="text" />
<yav:mask name="myDateMask" format="  /  /    " chars="0123456789" />
<yav:rule value="birthdate|mask|myDateMask" />

Architecture

At the client side YAV-tags simply generates the Javascript and HTML code required by YAV library.

While generating this Javascript code YAV rules are stored into the web application's ServletContext object, mapped to the form instance.

When form date is sent to server, request is intercepted by a servlet filter, who checks stored validation rules.

In case of a validation error, it shows encountered errors via a ServletException.

Technical documentation