<?xml version="1.0" encoding="UTF-8"?>
<section>
          <sectioninfo>
                    <keywordset>
                              <keyword>rich:beanValidator</keyword>
                    </keywordset>
          </sectioninfo>

          <table>
                    <title>Component identification parameters</title>

                    <tgroup cols="2">
                              <thead>
                                        <row>
                                                  <entry>Name</entry>

                                                  <entry>Value</entry>
                                        </row>
                              </thead>

                              <tbody>
                                        <row>
                                                  <entry>component-type</entry>

                                                  <entry>org.richfaces.beanValidator</entry>
                                        </row>

                                        <row>
                                                  <entry>component-class</entry>

                                                  <entry>org.richfaces.component.html.HtmlbeanValidator</entry>
                                        </row>

                                        <row>
                                                  <entry>component-family</entry>

                                                  <entry>org.richfaces.beanValidator</entry>
                                        </row>

                                        <row>
                                                  <entry>renderer-type</entry>

                                                  <entry>org.richfaces.beanValidatorRenderer</entry>
                                        </row>

                                        <row>
                                                  <entry>tag-class</entry>

                                                  <entry>org.richfaces.taglib.beanValidatorTag</entry>
                                        </row>
                              </tbody>
                    </tgroup>
          </table>

          <section>
                    <title>Creating the Component with a Page Tag</title>

                    <para>To create the simplest variant of the component on a page use the
                              following syntax:</para>


                    <para>
                              <emphasis role="bold">Example:</emphasis>
                    </para>
                    <programlisting role="XML"><![CDATA[...
<h:inputText value="#{validationBean.email}" id="email">
       <rich:beanValidator summary="Invalid email"/>
</h:inputText>
...]]></programlisting>
          </section>

          <section>
                    <title>Creating the Component Dynamically Using Java</title>

                    <para>
                              <emphasis role="bold">Example:</emphasis>
                    </para>
                    <programlisting role="JAVA"><![CDATA[import org.richfaces.component.html.HtmlCalendar; 	
...
HtmlbeanValidator mybeanValidator= new HtmlbeanValidator();
...
]]></programlisting>
          </section>

                    <!-- Start  Details of Usage-->
                    <section>
                              <title>Details of Usage</title>

                              <para> Starting from 3.2.2 GA version Rich Faces provides support for
                                        model-based constraints defined using Hibernate Validator.
                                        Thus it's possible to use Hibernate Validators the same as
                                        for Seam based applications. </para>

                              <para>The <emphasis role="bold">
                                                  <property>&lt;rich:beanValidator&gt;</property>
                                        </emphasis> component is defined in the same way as any JSF
                                        validator. Look at the example below. </para>

                              <programlisting role="XML"><![CDATA[...
<rich:panel>
       <f:facet name="header">
              <h:outputText value="#{validationBean.progressString}" id="progress"/>
       </f:facet>
       <h:panelGrid columns="3">
              <h:outputText value="Name:" />
              <h:inputText value="#{validationBean.name}" id="name">
                     <rich:beanValidator summary="Invalid name"/>
              </h:inputText>
              <rich:message for="name" />
              <h:outputText value="Email:" />
              <h:inputText value="#{validationBean.email}" id="email">
                     <rich:beanValidator summary="Invalid email"/>
              </h:inputText>
              <rich:message for="email" />
              <f:facet name="footer">
                     <a4j:commandButton value="Submit" action="#{validationBean.success}" reRender="progress"/>
              </f:facet>
       </h:panelGrid>
</rich:panel>
...]]></programlisting>

                              <para>Please play close attention on the bean code that contains the
                                        constraints defined with Hibernate annotation which perform
                                        validation of the input data.</para>

                              <programlisting role="JAVA"><![CDATA[
package org.richfaces.demo.validation;

import org.hibernate.validator.Email;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;

public class ValidationBean {

    @NotEmpty
    @Length(min=3,max=12)
    private String name;
    @Email
    @NotEmpty
    private String email;
    
    public ValidationBean() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}]]></programlisting>

                              <para>The following figure shows what happens if validation fails</para>

                              <figure>
                                        <title><emphasis role="bold">
                                                  <property>&lt;rich:beanValidator&gt;</property>
                                                  </emphasis> usage</title>
                                        <mediaobject>
                                                  <imageobject>
                                                  <imagedata
                                                  fileref="images/beanValidator1.png"
                                                  />
                                                  </imageobject>
                                        </mediaobject>
                              </figure>
                              <para>As you can see from the example that in order to validate the
                                                  <emphasis role="bold">
                                                  <property>&lt;rich:beanValidator&gt;</property>
                                        </emphasis> should be nested into a input JSF or RichFaces
                                        component. </para>

                              <para>The component has the only attribute - <emphasis>
                                                  <property>&quot;summary&quot;</property>
                                        </emphasis>which displays validation messages about
                                        validation errors.</para>
                    </section>
           


          <section>
                    <title>Relevant Resources Links</title>
                    <para><ulink url="http://livedemo.exadel.com/richfaces-demo/richfaces/beanValidator.jsf?c=beanValidator">
                              On RichFaces LiveDemo page </ulink> you can see an example of <emphasis role="bold"><property>&lt;rich:beanValidator&gt;</property>
                              </emphasis> usage and sources for the given example. </para>
          </section>

</section>
