Package org.xulfaces.rubis.web.faces

Source Code of org.xulfaces.rubis.web.faces.RegionConverter

package org.xulfaces.rubis.web.faces;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.el.ValueBinding;

import org.xulfaces.rubis.admin.dao.RegionDAO;
import org.xulfaces.rubis.admin.dao.RegionNotFoundException;
import org.xulfaces.rubis.model.Region;

public class RegionConverter implements Converter {

  public Object getAsObject(FacesContext context, UIComponent component, String value) {
    if(value!=null){
      int regionId = Integer.parseInt(value);
      ValueBinding valueBinding = context.getApplication().createValueBinding("#{regionDAO}");
      RegionDAO regionDAO = (RegionDAO) valueBinding.getValue(context);
      try {
        return regionDAO.loadRegion(new Integer(regionId));
      } catch (RegionNotFoundException e) {
        return null;
      }     
    }
    return null;
  }

  public String getAsString(FacesContext context, UIComponent component, Object value) {
    if(value instanceof Region){
      Region region = (Region) value;
      return region.getId().toString();
    }
    return null;
  }

}
TOP

Related Classes of org.xulfaces.rubis.web.faces.RegionConverter

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.