### Create new RichFaces Documentation Jira issue

Summary
255 characters left
Description
Environment
This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.org Community Documentation

- Prev
- Next

### 6.3.3. < rich:graphValidator > available since 3.2.2

expand all

#### 6.3.3.1. Description

The <rich:graphValidator> component allows to register Hibernate Validators for multiple input components.

#### 6.3.3.2. Key Features

- Skips all JSF processing except validation

Table 6.38. rich : graphValidator attributes

Attribute Name | Description
--- | ---
binding | JSF: The attribute takes a value-binding expression for a component property of a backing bean
id | JSF: Every component may have a unique id that is automatically created if omitted
profiles | This attribute defines JavaBean Validation 'groups' feature (JSR-303). It is ignored if Hibernate Validator is used.
summary | Summary message for a validation errors.
type | HTML: JSF Validator type, that implements GraphValidator interface.This validator is used for the Graph and input fields validation.
value | JSF: The current value for this component.

Table 6.39. Component identification parameters

Name | Value
--- | ---
component-type | org.richfaces.graphValidator
component-class | org.richfaces.component.html.HtmlgraphValidator
component-family | org.richfaces.graphValidator
renderer-type | org.richfaces.graphValidatorRenderer
tag-class | org.richfaces.taglib.graphValidatorTag

#### 6.3.3.3. Creating the Component with a Page Tag

To create the simplest variant on a page use the following syntax:

Example:

    ...

    <h:outputText value="Name:" />

    <h:inputText value="#{userBean.name}" id="name" required="true">

              <f:validateLength minimum="3" maximum="12"/>

              <rich:graphValidator event="onblur"/>

    </h:inputText>

    ...

#### 6.3.3.4. Creating the Component Dynamically Using Java

Example:

    import org.richfaces.component.html.HtmlCalendar;

    ...

    HtmlgraphValidator mygraphValidator= new HtmlgraphValidator();

    ...

#### 6.3.3.5. Details of usage

The <rich:graphValidator> component behaves basically the same way as the <rich:beanValidator> The deference between these two components is that in order to validate some input data with a <rich:beanValidator> component, it should be a nested element of an input component, whereas <rich:graphValidator> wraps multiple input components and validates the data received from them.

The following example demonstrates a pattern of how the <rich:graphValidator> can be used:

    ...

    <rich:graphValidator>

         <h:panelGrid columns="3">

              <h:outputText value="Name:" />

              <h:inputText value="#{validationBean.name}" id="name">

                   <f:validateLength minimum="2" />

              </h:inputText>

              <rich:message for="name" />

              <h:outputText value="Email:" />

              <h:inputText value="#{validationBean.email}" id="email" />

              <rich:message for="email" />

         </h:panelGrid>

    </rich:graphValidator>

    ...

The data validation can be also performed using Hibernate Validator, the same way as it is done with <rich:beanValidator> .

The components's architecture provides an option to bind the component to a managed bean, which is done with the "value" attribute. The attribute ensures that the entered data is valid after the model is updated by revalidating the bean properties.

Please look at the example below.

    ...

    <rich:graphValidator summary="Invalid values: " value="#{dayStatistics}">

         <a4j:repeat value="#{dayStatistics.dayPasstimes}" var="pt" id="table">

              <h:outputText value="#{pt.title}" />

              <rich:inputNumberSpinner minValue="0" maxValue="24" value="#{pt.time}" id="time" />

              <rich:message for="time" />

         </a4j:repeat>

    </rich:graphValidator>

    ...

Hence, the given above code will provide the functionality that is illustrated on the images below.

Figure 6.9. "Games" field did not pass validation

As you can see from the picture the "Games" field did not pass validation, as <rich:graphValidator> can be used to perform validation of a single input item.

Figure 6.10. Total sum of all input values is incorrect

The figure above shows that the entered data was revalidated after all fields were completed, and the data did not pass revalidation since the total sum was incorrect.

#### 6.3.3.6. Relevant Resources Links

Visit the GraphValidator page at RichFaces LiveDemo for examples of component usage and their sources.

- Prev6.3.2. < rich:beanValidator > ...
- Top of page
- Front page
- Next6.4. Ajax Output