HTML and CSS Reference
In-Depth Information
The figure illustrates how JSF conversions and validations can occur in
Process Validations phase , for all the components which do not have immediate attribute
set to true .
Apply Request Values phase , for the components whose immediate="true" .
Render Response phase .
In both the Process Validations phase and the Apply Request Values phase, the conversion from the HTTP
Request String to the Java type occurs (using the getAsObject API in the JSF Converter interface), and then the JSF
validation is performed. While in the Render Response phase, the conversion from the Java type to String occurs
(using the getAsString API in the JSF Converter interface) in order to be ready for rendering.
notice that the immediate attribute can be applied to both the UICommand components (such as
CommandButton and CommandLink ) and to the EditableValueHolder components (such as inputText ).
Conversion can be applied to all the ValueHolder components (this includes UIOutput and UIInput— which
extends UIOutput— components), while the validation can be applied only on the EditableValueHolder components
(this includes UIInput components). In the next sections, the JSF conversion and the validation will be illustrated in
In order to understand the JSF conversion, we need to know three main topics: the Converter interface APIs, the
standard JSF converters, and finally how to build a custom converter in JSF. The next subsections illustrate these
topics in detail.
Converter Interface
All of the JSF converters must implement the javax.faces.convert.Converter interface. The Converter interface
describes a Java class that can perform Object-to-String and String-to-Object conversions between the model data
objects and a String representation of these model objects that is suitable for rendering. Listing 3-1 shows the JSF
Converter interface.
Listing 3-1. JSF Converter Interface
package javax.faces.convert;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
public interface Converter {
public Object getAsObject(FacesContext context, UIComponent component, String value);
public String getAsString(FacesContext context, UIComponent component, Object value);
Search WWH ::

Custom Search