SlideShare a Scribd company logo
1 of 34
OmniFaces Validators
Anghel Leonard
What we will cover ?
• JSF Validators – short overview
• OmniFaces Validators – short overview
• ValidateBean
• RequiredCheckboxValidator
• ValueChangeValidator
• ValidateUniqueColumn
• JsfLabelMessageInterpolator
• OmniFaces Validator family
JSF Validators – short overview (I)
• JSF developers are familiar with JSF built-in validators (which are
tag handlers) and JSF custom validators (implementations of
javax.faces.validator.Validator interface).
• Commonly, JSF validators are attached to inputs (e.g. <h:inputText>)
via validator attribute or <f:validator>/<f:validateXxx> tags.
JSF Validators – short overview (II)
• JSF validators are by default processed in the Process Validations
phase. Converters are invoked in this phase (e.g. getAsObject()), but
in Render Response phase also (e.g. getAsString()).
• If the validation fails then JSF marks this via validationFailed flag, at
context level, and via valid flag, at input level.
• Moreover, the JSF lifecycle “jumps” to the Render Response phase,
instead of continue with the Update Model Values phase.
OmniFaces Validators – short overview (I)
• Some OmniFaces validators fixes a suite of gaps of the JSF
standard validators, while others are totally new.
• Depending on their goal, OmniFaces validators are implementations
of javax.faces.validator.Validator interface, are tag handlers (extends
TagHandler) or even UIComponent instances.
OmniFaces Validators – short overview (II)
• While JSF doesn’t support cross-field validation (not even for
<f:validateBean>), OmniFaces provides several validators that
implements different validation constrains for cross-field validation.
• OmniFaces validators are easy to use and the OmniFaces
Showcase provides complete and dedicated examples.
OmniFaces ValidateBean (I)
• The built-in <f:validateBean> allows validation control only on a per-
form or a per-request basis, and only applies to individual properties
of a bean
• The OmniFaces <o:validateBean> allows the developer to control
bean validation on a per-UICommand or UIInput component basis, as
well as validating a bean at the class level
OmniFaces ValidateBean (II)
• At class level, validation can be of two types: validate copy and
validate actual bean.
• Validate copy (default) - make a copy of the object to validate at the
end of Process Validations phase, set the values retrieved from the
input components on it, and performs class level validation on the
copy. Does not update the model if validation errors occur.
• Validate actual bean - the validation takes places after the Update
Model Values, so the original bean is first updated with the values
retrieved from the input components, afterwards validated.
OmniFaces ValidateBean (III)
• Sample of using <o:validateBean> - screenshots from Showcase
Validating at the class level that number 1 is smaller
than number 2 - default (validate copy)
OmniFaces RequiredCheckboxValidator (I)
• If you need to report the un-ticked checkboxes as invalid inputs then
use the OmniFaces RequiredCheckboxValidator validator.
• The RequiredCheckboxValidator solves the problem with required="true"
attribute of UISelectBoolean components (<h:selectBooleanCheckbox>). In
case of UISelectBoolean the validation will pass for both, ticked/un-
ticked checkboxes.
OmniFaces RequiredCheckboxValidator (II)
• This validator is used by indicating the validator ID (validatorId
attribute) omnifaces.RequiredCheckboxValidator in <f:validator> of the
boolean selection component.
• The validator will use the message as specified in requiredMessage
attribute, or the default required message as specified in custom
<message-bundle> in faces-config.xml, or it will default to: {0}: a tick is
required.
OmniFaces RequiredCheckboxValidator(III)
• Sample of using RequiredCheckboxValidator - screenshots from Showcase
Form with RequiredCheckboxValidator
OmniFaces ValueChangeValidator (I)
• At each postback request, the validation process validates the
corresponding submitted values, regardless of whether the submitted
values has changed or not.
• Most likely, we don’t want to re-validate unchanged data.
• In terms of performance, these unnecessarily validations my becomes
too “expensive”. When that happens, is time for ValueChangeValidator.
• The ValueChangeValidator can be used via a transparent template.
Mainly, just replace implements Validator by extends ValueChangeValidator
and rename the method from validate to validateChangedObject.
OmniFaces ValueChangeValidator(II)
A JSF common custom validator modified to use ValueChangeValidator
• Sample of using ValueChangeValidator - screenshots from Showcase
A JSF common custom validator
OmniFaces ValidateUniqueColumn (I)
• The <o:validateUniqueColumn> validates if the given UIInput component in
an UIData component has an unique value throughout all rows. Those
not visible by pagination are also validated.
• This validator works directly on the data model and may therefore not
work as expected if the data model does not represent all available
rows of the UIData component (e.g. when there's means of lazy
loading).
OmniFaces ValidateUniqueColumn (II)
• In an invalidating case, only the first row on which the value is actually
changed will be marked invalid and a faces message will be added on
the client ID of the input component in the particular row.
• The default message is: {0}: Please fill out an unique value for the
entire column. Duplicate found in row {1}
OmniFaces ValidateUniqueColumn (III)
• Sample of using ValidateUniqueColumn- screenshots from Showcase
DataTable with ValidateUniqueColumn
OmniFaces JsfLabelMessageInterpolator(I)
• In Bean Validation, if a component causes a validation failure, then
the label associated with this component can appear only in the front
or behind the error message. This is possible thanks to
javax.faces.validator.BeanValidator.MESSAGE bundle key.
• OmniFaces comes with a custom message interpolator that allows
developers to place the label associated with the invalid component
anywhere in the error message.
OmniFaces JsfLabelMessageInterpolator(II)
• In order to use the JsfLabelMessageInterpolator, the developer must
register it in /META-INF/validation.xml via <message-interpolator> , and
use the special placeholder {jsf.label} in bean validation messages.
• Message example: javax.validation.constraints.Size.message = The size
of {jsf.label} must be between {min} and {max} characters
OmniFaces JsfLabelMessageInterpolator(III)
• Sample of using JsfLabelMessageInterpolator - screenshots from Showcase
Demo for JsfLabelMessageInterpolator
OmniFaces Validator family
The OmniFaces Validator family represents a collection of cross-field
validators implemented as JSF custom components. Below you can see
the Validator family API.
OmniFaces ValidateOne
• The <o:validateOne> validates if ONLY ONE of the given UIInput
components have been filled out.
• The default message is: {0}: Please fill out only one of those fields
Screenshots Showcase
OmniFaces ValidateOneOrMore
• The <o:validateOneOrMore> validates if at least ONE of the given UIInput
components has been filled out.
• The default message is: {0}: Please fill out at least one of those
fields
Screenshots Showcase
OmniFaces ValidateAllOrNone
• The <o:validateAllOrNone> validates if at least ALL of the given UIInput
components have been filled out or that NONE of the given UIInput
components have been filled out.
• The default message is: {0}: Please fill out all or none of those fields
Screenshots Showcase
You can also show message on all invalid fields, invalidate only the empty fields or
invalidate only the empty fields and show message only on invalid fields
OmniFaces ValidateOneOrNone
• The <o:validateOneOrNone> validates if ONLY ONE of the given UIInput
components has been filled out or that NONE of the given UIInput
components have been filled out.
• The default message is: {0}: Please fill out only one or none of those
fields
Screenshots Showcase
OmniFaces ValidateAll
• The <o:validateAll> validates if ALL of the given UIInput components
have been filled out. One could of course also just put required="true"
on all of those UIInput components, but this is not always the case
(e.g. having a single message for all invalid UIInput).
• The default message is: {0}: Please fill out all of those fields
Screenshots Showcase
OmniFaces ValidateEqual
• The <o:validateEqual> validates if ALL of the given UIInput components
have the same value.
• The default message is: {0}: Please fill out the same value for all of
those fields
Screenshots Showcase
OmniFaces ValidateUnique
• The <o:validateUnique> validates if ALL of the given UIInput
components have an unique value.
• The default message is: {0}: Please fill out an unique value for all of
those fields
Screenshots Showcase
OmniFaces ValidateOrder (I)
• The <o:validateOrder> validates if the values of the given UIInput
components as specified in the required components attribute are in the
order as specified by the optional type attribute which accepts the
following values:
• lt (default) - from least to greatest, without duplicates.
• lte - from least to greatest, allowing duplicates (equal values next to
each other).
• gt - from greatest to least, without duplicates.
• gte - from greatest to least, allowing duplicates (equal values next to
each other).
OmniFaces ValidateOrder (II)
• The to-be-validated values must implement Comparable.
• This validator throws an IllegalArgumentException when one or more of
the values do not implement it.
• Note that when this validator is placed before all of the components,
then it will only compare the raw unconverted submitted string values,
not the converted object values.
• If you need to compare by the converted object values, then you need
to place this validator after all of the components.
OmniFaces ValidateOrder (III)
• The <o:validateOrder> validates if the values of the given UIInput
respects a certain order.
• The default message is: {0}: Please fill out the values of all those
fields in order
Screenshots Showcase
OmniFaces ValidateMultiple (I)
• The <o:validateMultiple> allows the developer to validate multiple fields
by a custom validator method:
<!-- source code: OmniFaces Showcase -->
<o:validateMultiple id="myId" components="foo bar baz"
validator="#{bean.someMethod}" />
<h:message for="myId" />
<h:inputText id="foo" />
<h:inputText id="bar" />
<h:inputText id="baz" />
Method has the following signature (method name is free to your choice):
OmniFaces ValidateMultiple (II)
• The <o:validateMultiple> also allows to validate multiple fields by a
managed bean that implements the MultiFieldValidator interface:
<!-- source code: OmniFaces Showcase -->
<o:validateMultiple id="myId" components="foo bar baz"
validator="#{validateValuesBean}" />
<h:message for="myId" />
<h:inputText id="foo" />
<h:inputText id="bar" />
<h:inputText id="baz" />
Managed bean signature (bean name is free to your choice):
References
• Bauke Scholtz - http://balusc.blogspot.com/
• Arjan Tijms - http://arjan-tijms.omnifaces.org/
• JSF ZEEF page - https://jsf.zeef.com/bauke.scholtz
• OmniFaces ZEEF page - https://omnifaces.zeef.com/bauke.scholtz
• OmniFaces Wikipedia - http://en.wikipedia.org/wiki/OmniFaces

More Related Content

What's hot

Customizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UICustomizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UITech OneStop
 
Effective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjectsEffective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjectsSrikanth Shenoy
 
Siebel Open UI Debugging (Siebel Open UI Training, Part 7)
Siebel Open UI Debugging (Siebel Open UI Training, Part 7)Siebel Open UI Debugging (Siebel Open UI Training, Part 7)
Siebel Open UI Debugging (Siebel Open UI Training, Part 7)Tech OneStop
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web ApplicationYakov Fain
 
Spring REST Request Validation
Spring REST Request ValidationSpring REST Request Validation
Spring REST Request ValidationMohammad Sabir Khan
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFXHendrik Ebbers
 
Java Custom Annotations- Part1
Java Custom Annotations- Part1Java Custom Annotations- Part1
Java Custom Annotations- Part1Mohammad Sabir Khan
 
Request Validation In Spring Rest-Part2
Request Validation In Spring Rest-Part2Request Validation In Spring Rest-Part2
Request Validation In Spring Rest-Part2Mohammad Sabir Khan
 
JSF basics
JSF basicsJSF basics
JSF basicsairbo
 
OLT open script
OLT open script OLT open script
OLT open script Sujay Raghuraj
 
RichFaces 4: Rich Ajax Components For Your JSF Applications
RichFaces 4: Rich Ajax Components For Your JSF ApplicationsRichFaces 4: Rich Ajax Components For Your JSF Applications
RichFaces 4: Rich Ajax Components For Your JSF ApplicationsMax Katz
 
Skillwise EJB3.0 training
Skillwise EJB3.0 trainingSkillwise EJB3.0 training
Skillwise EJB3.0 trainingSkillwise Group
 
Selenium Basics Tutorial
Selenium Basics TutorialSelenium Basics Tutorial
Selenium Basics TutorialClever Moe
 
JavaFX8 TestFX - CDI
JavaFX8   TestFX - CDIJavaFX8   TestFX - CDI
JavaFX8 TestFX - CDISven Ruppert
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design PatternsLilia Sfaxi
 

What's hot (20)

Customizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UICustomizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UI
 
Effective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjectsEffective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjects
 
Siebel Open UI Debugging (Siebel Open UI Training, Part 7)
Siebel Open UI Debugging (Siebel Open UI Training, Part 7)Siebel Open UI Debugging (Siebel Open UI Training, Part 7)
Siebel Open UI Debugging (Siebel Open UI Training, Part 7)
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
 
Spring REST Request Validation
Spring REST Request ValidationSpring REST Request Validation
Spring REST Request Validation
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
Java Custom Annotations- Part1
Java Custom Annotations- Part1Java Custom Annotations- Part1
Java Custom Annotations- Part1
 
Request Validation In Spring Rest-Part2
Request Validation In Spring Rest-Part2Request Validation In Spring Rest-Part2
Request Validation In Spring Rest-Part2
 
Spring core
Spring coreSpring core
Spring core
 
JSF basics
JSF basicsJSF basics
JSF basics
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring aop
Spring aopSpring aop
Spring aop
 
OLT open script
OLT open script OLT open script
OLT open script
 
RichFaces 4: Rich Ajax Components For Your JSF Applications
RichFaces 4: Rich Ajax Components For Your JSF ApplicationsRichFaces 4: Rich Ajax Components For Your JSF Applications
RichFaces 4: Rich Ajax Components For Your JSF Applications
 
Spring jdbc
Spring jdbcSpring jdbc
Spring jdbc
 
Skillwise EJB3.0 training
Skillwise EJB3.0 trainingSkillwise EJB3.0 training
Skillwise EJB3.0 training
 
Maven
MavenMaven
Maven
 
Selenium Basics Tutorial
Selenium Basics TutorialSelenium Basics Tutorial
Selenium Basics Tutorial
 
JavaFX8 TestFX - CDI
JavaFX8   TestFX - CDIJavaFX8   TestFX - CDI
JavaFX8 TestFX - CDI
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 

Viewers also liked

Viewers also liked (15)

Risk and Sustainability-Russ Doak rev 1
Risk and Sustainability-Russ Doak rev 1Risk and Sustainability-Russ Doak rev 1
Risk and Sustainability-Russ Doak rev 1
 
Biografi Abdurachman Wahid
Biografi Abdurachman WahidBiografi Abdurachman Wahid
Biografi Abdurachman Wahid
 
109168
109168109168
109168
 
Practica 7
Practica 7 Practica 7
Practica 7
 
Dossier de presse English
Dossier de presse EnglishDossier de presse English
Dossier de presse English
 
Sorrow Magazine
Sorrow MagazineSorrow Magazine
Sorrow Magazine
 
Airports_Systems
Airports_SystemsAirports_Systems
Airports_Systems
 
Product research
Product researchProduct research
Product research
 
Prezentacja 2015
Prezentacja 2015Prezentacja 2015
Prezentacja 2015
 
Painting with lights
Painting with lightsPainting with lights
Painting with lights
 
Ishak 009
Ishak 009Ishak 009
Ishak 009
 
If you can't beat em, join em
If you can't beat em, join emIf you can't beat em, join em
If you can't beat em, join em
 
John Eberhardt NSTAC Testimony
John Eberhardt NSTAC TestimonyJohn Eberhardt NSTAC Testimony
John Eberhardt NSTAC Testimony
 
CarolinaCon Presentation on Streaming Analytics
CarolinaCon Presentation on Streaming AnalyticsCarolinaCon Presentation on Streaming Analytics
CarolinaCon Presentation on Streaming Analytics
 
CATALOGUE ENG
CATALOGUE ENGCATALOGUE ENG
CATALOGUE ENG
 

Similar to OmniFaces validators

Angular genericforms2
Angular genericforms2Angular genericforms2
Angular genericforms2Eliran Eliassy
 
Validation in asp.net
Validation in asp.netValidation in asp.net
Validation in asp.netSireesh K
 
Unit Tesing in iOS
Unit Tesing in iOSUnit Tesing in iOS
Unit Tesing in iOSCiklum Ukraine
 
What are Anypoint Validations With Mulesoft
What are Anypoint Validations With Mulesoft What are Anypoint Validations With Mulesoft
What are Anypoint Validations With Mulesoft Jitendra Bafna
 
Bridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous DeliveryBridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous Deliverymasoodjan
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.netDeep Patel
 
Testing Angular
Testing AngularTesting Angular
Testing AngularLilia Sfaxi
 
Tdd iPhone For Dummies
Tdd iPhone For DummiesTdd iPhone For Dummies
Tdd iPhone For DummiesGiordano Scalzo
 
Selenium using Java
Selenium using JavaSelenium using Java
Selenium using JavaF K
 
Java EE 7 Recipes
Java EE 7 RecipesJava EE 7 Recipes
Java EE 7 RecipesJosh Juneau
 
Introduction to Custom Form Control
Introduction to Custom Form ControlIntroduction to Custom Form Control
Introduction to Custom Form ControlKnoldus Inc.
 
Multiple Submit Button Test App
Multiple Submit Button Test AppMultiple Submit Button Test App
Multiple Submit Button Test AppPeeyush Ranjan
 
Selenium (1) (1)
Selenium (1) (1)Selenium (1) (1)
Selenium (1) (1)Vishwan Aranha
 
Selenium
SeleniumSelenium
SeleniumBatch2016
 
Selenium
SeleniumSelenium
SeleniumBatch2016
 
Selenium
SeleniumSelenium
SeleniumBatch2016
 

Similar to OmniFaces validators (20)

Angular genericforms2
Angular genericforms2Angular genericforms2
Angular genericforms2
 
Validation in asp.net
Validation in asp.netValidation in asp.net
Validation in asp.net
 
Unit Tesing in iOS
Unit Tesing in iOSUnit Tesing in iOS
Unit Tesing in iOS
 
What are Anypoint Validations With Mulesoft
What are Anypoint Validations With Mulesoft What are Anypoint Validations With Mulesoft
What are Anypoint Validations With Mulesoft
 
Bridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous DeliveryBridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous Delivery
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.net
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
Tdd iPhone For Dummies
Tdd iPhone For DummiesTdd iPhone For Dummies
Tdd iPhone For Dummies
 
Selenium using Java
Selenium using JavaSelenium using Java
Selenium using Java
 
Java EE 7 Recipes
Java EE 7 RecipesJava EE 7 Recipes
Java EE 7 Recipes
 
Introduction to Custom Form Control
Introduction to Custom Form ControlIntroduction to Custom Form Control
Introduction to Custom Form Control
 
JSF Security
JSF SecurityJSF Security
JSF Security
 
Wheels
WheelsWheels
Wheels
 
Multiple Submit Button Test App
Multiple Submit Button Test AppMultiple Submit Button Test App
Multiple Submit Button Test App
 
Selenium (1) (1)
Selenium (1) (1)Selenium (1) (1)
Selenium (1) (1)
 
Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 

Recently uploaded

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
2.pdf Ejercicios de programaciĂłn competitiva
2.pdf Ejercicios de programaciĂłn competitiva2.pdf Ejercicios de programaciĂłn competitiva
2.pdf Ejercicios de programaciĂłn competitivaDiego IvĂĄn Oliveros Acosta
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessEnvertis Software Solutions
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
2.pdf Ejercicios de programaciĂłn competitiva
2.pdf Ejercicios de programaciĂłn competitiva2.pdf Ejercicios de programaciĂłn competitiva
2.pdf Ejercicios de programaciĂłn competitiva
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 

OmniFaces validators

  • 2. What we will cover ? • JSF Validators – short overview • OmniFaces Validators – short overview • ValidateBean • RequiredCheckboxValidator • ValueChangeValidator • ValidateUniqueColumn • JsfLabelMessageInterpolator • OmniFaces Validator family
  • 3. JSF Validators – short overview (I) • JSF developers are familiar with JSF built-in validators (which are tag handlers) and JSF custom validators (implementations of javax.faces.validator.Validator interface). • Commonly, JSF validators are attached to inputs (e.g. <h:inputText>) via validator attribute or <f:validator>/<f:validateXxx> tags.
  • 4. JSF Validators – short overview (II) • JSF validators are by default processed in the Process Validations phase. Converters are invoked in this phase (e.g. getAsObject()), but in Render Response phase also (e.g. getAsString()). • If the validation fails then JSF marks this via validationFailed flag, at context level, and via valid flag, at input level. • Moreover, the JSF lifecycle “jumps” to the Render Response phase, instead of continue with the Update Model Values phase.
  • 5. OmniFaces Validators – short overview (I) • Some OmniFaces validators fixes a suite of gaps of the JSF standard validators, while others are totally new. • Depending on their goal, OmniFaces validators are implementations of javax.faces.validator.Validator interface, are tag handlers (extends TagHandler) or even UIComponent instances.
  • 6. OmniFaces Validators – short overview (II) • While JSF doesn’t support cross-field validation (not even for <f:validateBean>), OmniFaces provides several validators that implements different validation constrains for cross-field validation. • OmniFaces validators are easy to use and the OmniFaces Showcase provides complete and dedicated examples.
  • 7. OmniFaces ValidateBean (I) • The built-in <f:validateBean> allows validation control only on a per- form or a per-request basis, and only applies to individual properties of a bean • The OmniFaces <o:validateBean> allows the developer to control bean validation on a per-UICommand or UIInput component basis, as well as validating a bean at the class level
  • 8. OmniFaces ValidateBean (II) • At class level, validation can be of two types: validate copy and validate actual bean. • Validate copy (default) - make a copy of the object to validate at the end of Process Validations phase, set the values retrieved from the input components on it, and performs class level validation on the copy. Does not update the model if validation errors occur. • Validate actual bean - the validation takes places after the Update Model Values, so the original bean is first updated with the values retrieved from the input components, afterwards validated.
  • 9. OmniFaces ValidateBean (III) • Sample of using <o:validateBean> - screenshots from Showcase Validating at the class level that number 1 is smaller than number 2 - default (validate copy)
  • 10. OmniFaces RequiredCheckboxValidator (I) • If you need to report the un-ticked checkboxes as invalid inputs then use the OmniFaces RequiredCheckboxValidator validator. • The RequiredCheckboxValidator solves the problem with required="true" attribute of UISelectBoolean components (<h:selectBooleanCheckbox>). In case of UISelectBoolean the validation will pass for both, ticked/un- ticked checkboxes.
  • 11. OmniFaces RequiredCheckboxValidator (II) • This validator is used by indicating the validator ID (validatorId attribute) omnifaces.RequiredCheckboxValidator in <f:validator> of the boolean selection component. • The validator will use the message as specified in requiredMessage attribute, or the default required message as specified in custom <message-bundle> in faces-config.xml, or it will default to: {0}: a tick is required.
  • 12. OmniFaces RequiredCheckboxValidator(III) • Sample of using RequiredCheckboxValidator - screenshots from Showcase Form with RequiredCheckboxValidator
  • 13. OmniFaces ValueChangeValidator (I) • At each postback request, the validation process validates the corresponding submitted values, regardless of whether the submitted values has changed or not. • Most likely, we don’t want to re-validate unchanged data. • In terms of performance, these unnecessarily validations my becomes too “expensive”. When that happens, is time for ValueChangeValidator. • The ValueChangeValidator can be used via a transparent template. Mainly, just replace implements Validator by extends ValueChangeValidator and rename the method from validate to validateChangedObject.
  • 14. OmniFaces ValueChangeValidator(II) A JSF common custom validator modified to use ValueChangeValidator • Sample of using ValueChangeValidator - screenshots from Showcase A JSF common custom validator
  • 15. OmniFaces ValidateUniqueColumn (I) • The <o:validateUniqueColumn> validates if the given UIInput component in an UIData component has an unique value throughout all rows. Those not visible by pagination are also validated. • This validator works directly on the data model and may therefore not work as expected if the data model does not represent all available rows of the UIData component (e.g. when there's means of lazy loading).
  • 16. OmniFaces ValidateUniqueColumn (II) • In an invalidating case, only the first row on which the value is actually changed will be marked invalid and a faces message will be added on the client ID of the input component in the particular row. • The default message is: {0}: Please fill out an unique value for the entire column. Duplicate found in row {1}
  • 17. OmniFaces ValidateUniqueColumn (III) • Sample of using ValidateUniqueColumn- screenshots from Showcase DataTable with ValidateUniqueColumn
  • 18. OmniFaces JsfLabelMessageInterpolator(I) • In Bean Validation, if a component causes a validation failure, then the label associated with this component can appear only in the front or behind the error message. This is possible thanks to javax.faces.validator.BeanValidator.MESSAGE bundle key. • OmniFaces comes with a custom message interpolator that allows developers to place the label associated with the invalid component anywhere in the error message.
  • 19. OmniFaces JsfLabelMessageInterpolator(II) • In order to use the JsfLabelMessageInterpolator, the developer must register it in /META-INF/validation.xml via <message-interpolator> , and use the special placeholder {jsf.label} in bean validation messages. • Message example: javax.validation.constraints.Size.message = The size of {jsf.label} must be between {min} and {max} characters
  • 20. OmniFaces JsfLabelMessageInterpolator(III) • Sample of using JsfLabelMessageInterpolator - screenshots from Showcase Demo for JsfLabelMessageInterpolator
  • 21. OmniFaces Validator family The OmniFaces Validator family represents a collection of cross-field validators implemented as JSF custom components. Below you can see the Validator family API.
  • 22. OmniFaces ValidateOne • The <o:validateOne> validates if ONLY ONE of the given UIInput components have been filled out. • The default message is: {0}: Please fill out only one of those fields Screenshots Showcase
  • 23. OmniFaces ValidateOneOrMore • The <o:validateOneOrMore> validates if at least ONE of the given UIInput components has been filled out. • The default message is: {0}: Please fill out at least one of those fields Screenshots Showcase
  • 24. OmniFaces ValidateAllOrNone • The <o:validateAllOrNone> validates if at least ALL of the given UIInput components have been filled out or that NONE of the given UIInput components have been filled out. • The default message is: {0}: Please fill out all or none of those fields Screenshots Showcase You can also show message on all invalid fields, invalidate only the empty fields or invalidate only the empty fields and show message only on invalid fields
  • 25. OmniFaces ValidateOneOrNone • The <o:validateOneOrNone> validates if ONLY ONE of the given UIInput components has been filled out or that NONE of the given UIInput components have been filled out. • The default message is: {0}: Please fill out only one or none of those fields Screenshots Showcase
  • 26. OmniFaces ValidateAll • The <o:validateAll> validates if ALL of the given UIInput components have been filled out. One could of course also just put required="true" on all of those UIInput components, but this is not always the case (e.g. having a single message for all invalid UIInput). • The default message is: {0}: Please fill out all of those fields Screenshots Showcase
  • 27. OmniFaces ValidateEqual • The <o:validateEqual> validates if ALL of the given UIInput components have the same value. • The default message is: {0}: Please fill out the same value for all of those fields Screenshots Showcase
  • 28. OmniFaces ValidateUnique • The <o:validateUnique> validates if ALL of the given UIInput components have an unique value. • The default message is: {0}: Please fill out an unique value for all of those fields Screenshots Showcase
  • 29. OmniFaces ValidateOrder (I) • The <o:validateOrder> validates if the values of the given UIInput components as specified in the required components attribute are in the order as specified by the optional type attribute which accepts the following values: • lt (default) - from least to greatest, without duplicates. • lte - from least to greatest, allowing duplicates (equal values next to each other). • gt - from greatest to least, without duplicates. • gte - from greatest to least, allowing duplicates (equal values next to each other).
  • 30. OmniFaces ValidateOrder (II) • The to-be-validated values must implement Comparable. • This validator throws an IllegalArgumentException when one or more of the values do not implement it. • Note that when this validator is placed before all of the components, then it will only compare the raw unconverted submitted string values, not the converted object values. • If you need to compare by the converted object values, then you need to place this validator after all of the components.
  • 31. OmniFaces ValidateOrder (III) • The <o:validateOrder> validates if the values of the given UIInput respects a certain order. • The default message is: {0}: Please fill out the values of all those fields in order Screenshots Showcase
  • 32. OmniFaces ValidateMultiple (I) • The <o:validateMultiple> allows the developer to validate multiple fields by a custom validator method: <!-- source code: OmniFaces Showcase --> <o:validateMultiple id="myId" components="foo bar baz" validator="#{bean.someMethod}" /> <h:message for="myId" /> <h:inputText id="foo" /> <h:inputText id="bar" /> <h:inputText id="baz" /> Method has the following signature (method name is free to your choice):
  • 33. OmniFaces ValidateMultiple (II) • The <o:validateMultiple> also allows to validate multiple fields by a managed bean that implements the MultiFieldValidator interface: <!-- source code: OmniFaces Showcase --> <o:validateMultiple id="myId" components="foo bar baz" validator="#{validateValuesBean}" /> <h:message for="myId" /> <h:inputText id="foo" /> <h:inputText id="bar" /> <h:inputText id="baz" /> Managed bean signature (bean name is free to your choice):
  • 34. References • Bauke Scholtz - http://balusc.blogspot.com/ • Arjan Tijms - http://arjan-tijms.omnifaces.org/ • JSF ZEEF page - https://jsf.zeef.com/bauke.scholtz • OmniFaces ZEEF page - https://omnifaces.zeef.com/bauke.scholtz • OmniFaces Wikipedia - http://en.wikipedia.org/wiki/OmniFaces