Package ru.portnyagin.helpdeskru.converter

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

/**
*
* @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.HistoryRequest;
import ru.portnyagin.helpdeskru.service.HistoryRequestService;
import ru.portnyagin.helpdeskru.util.EJB;

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

        HistoryRequest history = historyRequestService.find(Long.valueOf(value));

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

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

        return String.valueOf(((HistoryRequest) value).getId());
    }
   
   
   
   
   
}
TOP

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

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.