Validators

JSF has a well defined lifecycle splitted in different phases that perform specific operations against the view tree. One of those phases is the PROCESS_VALIDATIONS phase which triggers the validators attached to the different UIInput components.

JasperReports JSF Plugin provides its own validation mechanism triggered at the RENDER_RESPONSE lifecycle phase. The reason to use its own mechanism is based in following observations:

  • Report and data source components are not extensions of the UIInput component.
  • The PROCESS_VALIDATIONS phase is executed just when submitting information to the server. Something that is commonly called a post-back. Since we are rendering reports, we need a validation phase triggered just before render.
  • The library provides few components which act with different behavior depending of their properties. This has been done with the intention of ease of use, but since we're dealing with different possible values for the component properties, a validation step is required just before rendering.

    The built-in validation framework is very simple and, it's also very similar to the other providers implemented within this library.

    Validators are loaded used the ValidatorLoader class. The loading mechanism is based on locate inside the classpath a ValidatorFactory suitable to the current faces component.

Validator and Validator Factories

The library provides with two built-in ValidatorFactory implementations, one for data source components and another one for report components.

DataSource Validators

Data source components are validated using a DataSourceValidator. The DataSourceValidatorFactory will look inside the classpath for classes that implement the DataSourceValidator interface. These classes must be configured the same way FillerFactory instances are. Here is an example:

:net.sf.jasperreports.jsf.validation.DataSourceValidatorBase
jdbc:net.sf.jasperreports.jsf.validation.providers.JdbcDataSourceValidator

When no validator is found for the current data source type, the default one will be used. If no validator is found, the data source component will not be validated at all.

Report Validators

The same thing happens with reports. These are validated using a ReportValidator. The ReportValidatorFactory will look inside the classpath for classes that implement the ReportValidator interface. These classes must be configured the same way ExporterFactory instances are. Here is an example:

:net.sf.jasperreports.jsf.validation.ReportValidatorBase

When no validator is found for the current data source type, the default one will be used. If no validator is found, the data source component will not be validated at all.