HTML and CSS Reference
In-Depth Information
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
Location class is a simple Java bean that contains three attributes ( address , city , country ). In order to implement
our LocationConverter custom converter, we need to extend the JSF Converter interface and implement both the
getAsObject and getAsString methods. Listing 3-7 shows the LocationConverter implementation.
Listing 3-7. LocationConverter Class
package com.jsfprohtml5.example.converters;
import com.jsfprohtml5.example.model.Location;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
@FacesConverter("com.jsfprohtml5.LocationConverter")
public class LocationConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (null == value || 0 == value.length()) {
return null;
}
String locationParts[] = value.split(",");
if (locationParts.length != 3
|| locationParts[0].length() == 0
|| locationParts[1].length() == 0
|| locationParts[2].length() == 0) {
 
Search WWH ::




Custom Search