KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > component > UIIntegerInput


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.faces.core.component;
6
7 import java.util.Map JavaDoc ;
8 import java.io.IOException JavaDoc ;
9 import javax.faces.context.FacesContext;
10 import javax.faces.context.ResponseWriter;
11 import javax.faces.validator.Validator;
12 import javax.faces.validator.ValidatorException;
13 /**
14  * Wed, Dec 22, 2003 @ 23:14
15  * @author: Tuan Nguyen
16  * @email: tuan08@users.sourceforge.net
17  * @version: $Id: UIIntegerInput.java,v 1.3 2004/08/16 14:20:41 tuan08 Exp $
18  */

19 public class UIIntegerInput extends UIInput {
20   protected int value_ ;
21
22   public UIIntegerInput(String JavaDoc name, int value) {
23     name_ = name ;
24     value_ = value ;
25   }
26
27   final public int getValue() { return value_ ; }
28
29   final public UIIntegerInput setValue(int value) {
30     value_ = value ;
31     return this ;
32   }
33
34   public void decode(FacesContext context) {
35     Map JavaDoc paramMap = context.getExternalContext().getRequestParameterMap() ;
36     String JavaDoc value = (String JavaDoc) paramMap.get(name_) ;
37     if (value != null) {
38       try {
39         value_ = Integer.parseInt(value) ;
40         UISimpleForm form = (UISimpleForm) getParent() ;
41         form.setError(true) ;
42       } catch (NumberFormatException JavaDoc ex) {
43         error_ = true ;
44       }
45     }
46   }
47
48   public void processValidators(javax.faces.context.FacesContext context) {
49     if(validators_ != null) {
50       try {
51         Integer JavaDoc value = new Integer JavaDoc(value_) ;
52         for(int i = 0; i < validators_.size(); i++) {
53           Validator validator = (Validator) validators_.get(i) ;
54           validator.validate(context, this, value) ;
55         }
56       } catch(ValidatorException ex) {
57         error_ = true ;
58         throw ex ;
59       }
60     }
61   }
62   
63   public void encodeBegin(FacesContext context) throws IOException JavaDoc {
64     ResponseWriter w = context.getResponseWriter();
65     w.write("<input name='"); w.write(name_); w.write("'") ;
66     w.write(" value='"); w.write(Integer.toString(value_)); w.write("'") ;
67     if (getClazz() != null) {
68       w.write(" class='"); w.write(getClazz()); w.write("'") ;
69     }
70     w.write('>') ;
71   }
72 }
73
74
Popular Tags