Lecture 7 - Conversions and Validations Flashcards
What happens during request values phase?
Submitting a form will create a request value that is stored into the components.
What happens during the Process Validation phase?
Conversion attempts to cast submitted value to desired local value.
Local values validated.
What types do standard converters work with?
primitive, enum, BigInteger/BigDecimal
What is <f:convertNumber>?</f:convertNumber>
converts input into a type: number, currency or percent.
Can follow a formatting pattern=””
What is <f:convertDateTime>?</f:convertDateTime>
converts to type: date, time, localDate, localTime…
Can follow a formatting pattern=””
What is a converter attribute?
An alternative to having a <f:convertNumber> tag for example in the body.</f:convertNumber>
You can add the attribute converter=”javax.faces.DateTime” for example to an input tag
What happens during conversion errors?
Component declares itself invalid
JSF redisplays page with error messages using <h:message></h:message>
How are error messages displayed?
Using <h:message> or <h:messages> tag</h:messages></h:message>
Note: In JSF 2.0 <h:messages></h:messages> tag is
automatically added if project stage set to
Development
How do you change standard conversion error messages?
<message-bundle>com.corejsf.messages</message-bundle>
How is validation done?
Add validator component or method to a tag (custom validation).
What does immediate=”true” do in terms of validation?
Moves the process validations phase to occur in the apply request values phase.
Basically used to bypass validation, can be used with cancel commandButtons for example.
How is bean validation performed?
Add annotations to setters/getters
How are custom bean validators created?
@Constraint (validator class)
validator class implements ConstraintValidator
Changing bean validation default messages
Define ValidationMessages.properties in root package
What interface to implement for custom converter classes?
implement javax.faces.convert.Converter
Annotate with @FacesConverter(“converter id”)