Wednesday, November 3, 2010

wednesday, 03 nov

chapter 7 - the user interface component model

ActionSource2

ValueHolder

PartialStateHolder

NamingContainer

you have a component, a renderer and a tag handler

chapter 8 - converting and validating data
------------------------------------------

first conversion then validation

convertor

public Object getAsObject(FacesContext context,
UIComponent component,
String value)
public String getAsString(FacesContext context,
UIComponent component,
Object value)

u can have only one convertor max

if it's immediate - then the validation is done in apply request values phase

u have implicit conversion(when u have value binding) and explicit
conversion (when u specify a convertor by class of by convertor id)

u can also add programmatically a convertor

// Create the Converters, one by type, the other by Class.
intConverter =
context.getApplication( ).createConverter("javax.faces.Integer");
floatConverter =
context.getApplication( ).createConverter(Float.class);
// Install the converters.
component1.setConverter(intConverter);
component2.setConverter(floatConverter);

if you register a convertor by class
then it can be used for implicit conversion


validator interface

public void validate(FacesContext context,
UIComponent component,
Object value)

before validating the component is marked as invalid

validators are registered only by validator-id

u can make jsf not validate empty fields


javax.faces.VALIDATE_EMPTY_FIELDS
false


As an alternative to the required attribute, it is possible to nest an
element within any input component to achieve the same effect.

It’s very important to note that, when nesting, any validators, or settings on validators,
that happen inside of the nesting take precedence over whatever validators or settings are
specified on the wrapping validator(s).

standard validators have a property disabled which can an el expression as value



so u can add a validator by
validator attribute
special tag (standard or by f:validator and providing validator id)
programmatically


The markup tags all result in a call to addValidator( ) on the underlying
component instance, and the required attribute results in a call to setRequired(true) on the
component.

Bean Validation

@ManagedBean
@SessionScoped
public class UserBean {
protected String sex;
@NotEmpty(message="You must supply an email address")
@Email
protected String email;

!!! The FacesContext is an object per request

FacesMessage - severity, summary and detail


FacesContext contains two lists of messages
- associated with a component
- not associated with a component


different variants of the getMessages( ) method on
FacesContext. The variant that takes no arguments returns an Iterator of all messages, associated with a component or not. The variant that takes a clientId gets only messages associated with the component of that clientId, or, if the clientId is null, gets only messages that are not associated with a specific clientId.

The FacesContext is the place where you obtain the UIViewRoot for the current view

There are exactly three times in the request processing lifecycle when the standard
components will create a FacesMessage instance and add it to the FacesContext: when
conversion fails, when validation fails, or when the converted and validated data cannot be pushed to the model during the Update Model Values phase.


com.jsfcompref.Messages

en
de



You can also override the message using the requiredMessage, converterMessage, or
validatorMessage property of UIInput. This is exposed as a tag attribute on all of the tags that expose UIInput components to the page author.

@Email(message="Silly user, your email is invalid")
private String email;

@Email(domain=".org")
private String email;
The entry in the ValidationMessages_en.properties file is shown next:
validator.email=Invalid email address. Must end in {domain}.

chapter 9 - The JSF Event Model
---------------------------
There are two broad categories of events in JSF, application events and lifecycle events.

James Blunt - Stay the night

No comments: