1 package org.demo; 2 import javax.faces.component.UIComponent; 3 import javax.faces.context.FacesContext; 4 import javax.faces.convert.Converter; 5 6 public class CustomerConverter implements Converter { 7 8 public Object getAsObject(FacesContext facesContext, UIComponent uIComponent, String string) { 9 CustomerController controller = (CustomerController) facesContext.getApplication().getELResolver().getValue( 10 facesContext.getELContext(), null, "customer"); 11 Integer id = new Integer (string); 12 return controller.findCustomer(id); 13 } 14 15 public String getAsString(FacesContext facesContext, UIComponent uIComponent, Object object) { 16 if(object instanceof Customer) { 17 Customer o = (Customer) object; 18 return "" + o.getCustomerId(); 19 } else { 20 throw new IllegalArgumentException ("object:" + object + " of type:" + object.getClass().getName() + "; expected type: org.demo.Customer"); 21 } 22 } 23 } 24 | Popular Tags |