com.mycompany.CRMFly.Converters.ContactConverter.java Source code

Java tutorial

Introduction

Here is the source code for com.mycompany.CRMFly.Converters.ContactConverter.java

Source

/*
 * 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 com.mycompany.CRMFly.Converters;

import com.mycompany.CRMFly.ManagedBeans.ContactBean;
import java.io.Serializable;
import java.util.logging.Logger;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 *
 * @author ??
 */
//
//@ManagedBean
//@FacesConverter("contactConverter")
//@Scope("session")
@Component("contactConverter")
@Scope("session")
public class ContactConverter implements Converter, Serializable {

    @Autowired
    ContactBean contactBean;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {

        Long id = Long.parseLong(value.split(" ")[0]);
        return contactBean.getContactForId(id);

    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return value.toString();
    }
}