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

Java tutorial

Introduction

Here is the source code for com.mycompany.CRMFly.Converters.ClientConverter.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.ClientBean;
import java.io.Serializable;
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 ??
 */
//

@Component("clientConverter")
@Scope("session")
public class ClientConverter implements Converter, Serializable {

    @Autowired
    ClientBean clientBean;

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

        Long id = Long.parseLong(value.split(" ")[0]);
        //   String id= value.split(" ")[0];
        return clientBean.getClientForId(id);

    }

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

        return value.toString();
    }
}