Package ru.portnyagin.helpdeskru.converter

Source Code of ru.portnyagin.helpdeskru.converter.PriorityConverter

/**
*
* @author ilya portnyagin iportnyagin@gmail.com
*/

package ru.portnyagin.helpdeskru.converter;

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;
import ru.portnyagin.helpdeskru.model.Priority;
import ru.portnyagin.helpdeskru.service.PriorityService;
import ru.portnyagin.helpdeskru.util.EJB;

   
   
@FacesConverter(forClass = Priority.class)
public class PriorityConverter implements Converter {
   
    private PriorityService priorityService = EJB.lookup(PriorityService.class);
   
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value == null || value.length() == 0){
            return null;
        }

        Priority priority = priorityService.find(value);

        if (priority == null) {
            throw new ConverterException(new FacesMessage("Unknown Priority ID: " + value));
        }

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

        return ((Priority) value).getId();
    }
   
   
   
   
   
}
TOP

Related Classes of ru.portnyagin.helpdeskru.converter.PriorityConverter

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.