Package jsf.entity

Source Code of jsf.entity.LecturesConverter

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package jsf.entity;

import entity.Lecture;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import jpa.controllers.LectureJpaController;

/**
*
* @author atap
*/
public class LecturesConverter implements Converter {
     @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value == null || value.length() == 0) {
            return null;
        }
        Integer id = new Integer(value);
        LectureJpaController controller = (LectureJpaController) context.getApplication().getELResolver().getValue(context.getELContext(), null, "lectureJpa");
        return controller.findLecture(id);
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value == null) {
            return null;
        }
        if (value instanceof Lecture) {
            Lecture o = (Lecture) value;
            return o.getId() == null ? "" : o.getId().toString();
        } else {
            throw new IllegalArgumentException("object " + value + " is of type " + value.getClass().getName() + "; expected type: entity.Lectures");
        }
    }
}
TOP

Related Classes of jsf.entity.LecturesConverter

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.