KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > demo > DiscountCodeConverter


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 DiscountCodeConverter implements Converter {
7
8     public Object JavaDoc getAsObject(FacesContext facesContext, UIComponent uIComponent, String JavaDoc string) {
9         DiscountCodeController controller = (DiscountCodeController) facesContext.getApplication().getELResolver().getValue(
10             facesContext.getELContext(), null, "discountCode");
11         String JavaDoc id = string;
12         return controller.findDiscountCode(id);
13     }
14
15     public String JavaDoc getAsString(FacesContext facesContext, UIComponent uIComponent, Object JavaDoc object) {
16         if(object instanceof DiscountCode) {
17             DiscountCode o = (DiscountCode) object;
18             return "" + o.getDiscountCode();
19         } else {
20             throw new IllegalArgumentException JavaDoc("object:" + object + " of type:" + object.getClass().getName() + "; expected type: org.demo.DiscountCode");
21         }
22     }
23 }
24
Popular Tags