Package com.mycompany.controllers

Source Code of com.mycompany.controllers.PersonaConverter

package com.mycompany.controllers;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.persistence.EntityManager;

import com.mycompany.model.Persona;
import com.mycompany.repository.PersonaRepository;
import com.mycompany.util.JpaUtil;

@FacesConverter(forClass = Persona.class)
public class PersonaConverter implements Converter {

  // @Inject no es soportado en un Converter
  private PersonaRepository personaRepository;

  public PersonaConverter() {
    personaRepository = CDILocator.getBean(PersonaRepository.class);
  }

  @Override
  public Object getAsObject(FacesContext context, UIComponent component,
      String value) {
    Persona retorno = null;

    if (value != null) {
      retorno = personaRepository.porId(new Long(value));
    }
    return retorno;

  }

  @Override
  public String getAsString(FacesContext context, UIComponent component,
      Object value) {
    if (value != null)
      return ((Persona) value).getId().toString();
    return null;
  }

}
TOP

Related Classes of com.mycompany.controllers.PersonaConverter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.