Created
July 7, 2014 00:57
-
-
Save manuel14/62ebe4b3f7b26f99a11c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package Converters; | |
import dacs.dao.TransporteFacade; | |
import dacs.models.Transporte; | |
import javax.ejb.EJB; | |
import javax.faces.component.UIComponent; | |
import javax.faces.context.FacesContext; | |
import javax.faces.convert.Converter; | |
import javax.faces.convert.FacesConverter; | |
/** | |
* | |
* @author Administrator | |
*/ | |
@FacesConverter(value = "TransporteConverter", forClass = Transporte.class) | |
public class TransporteConverter implements Converter{ | |
@EJB | |
private TransporteFacade transporteFacade; | |
@Override | |
public Object getAsObject(FacesContext context, UIComponent component, String value) { | |
if (value == null || value.isEmpty()) { | |
return null; | |
} | |
return transporteFacade.find(Integer.parseInt(value)); | |
} | |
@Override | |
public String getAsString(FacesContext context, UIComponent component, Object value) { | |
if (!value.getClass().equals(Transporte.class)) { | |
return null; | |
} | |
Transporte transporte = (Transporte) value; | |
return transporte.getIdtransporte().toString(); | |
} | |
/** | |
* Creates a new instance of TransporteConverter | |
*/ | |
public TransporteConverter() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment