/*
 * Arrebol Consultancy copyright.
 * 
 * This code belongs to Arrebol Consultancy
 * its use, redistribution or modification are prohibited 
 * without written authorization from Arrebol Consultancy.
 */
package com.arrebol.taxiservicios.convert;

import com.arrebol.taxiservicios.model.view.PersonListView;
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;

/**
 *
 * @author Carlos Janitzio Zavala Lopez <janitzio.zavala@arrebol.com.mx>
 */
@FacesConverter("personListViewConverter")
public class PersonListViewConverter implements Converter<PersonListView> {

    @Override
    public PersonListView getAsObject(FacesContext fc, UIComponent uic, String id) {
        try {
            return new PersonListView(id);
        } catch (Exception e) {
            throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error en búsqueda", "No se pudo obtener los datos del chofer búscado"));
        }
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, PersonListView person) {
        if (person != null) {
            return person.getId();
        } else {
            return null;
        }
    }

}
