KickJava   Java API By Example, From Geeks To Geeks.

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


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
9 import java.io.IOException JavaDoc ;
10
11 import javax.faces.context.FacesContext;
12 import javax.faces.context.ResponseWriter;
13 /**
14  * Wed, Dec 22, 2003 @ 23:14
15  * @author: Tuan Nguyen
16  * @email: tuan08@users.sourceforge.net
17  * @version: $Id: UICheckBox.java,v 1.4 2004/08/23 15:05:41 benjmestrallet Exp $
18  */

19 public class UICheckBox extends UIInput {
20   protected String JavaDoc value_ ;
21   protected boolean isCheck_ ;
22
23   public UICheckBox(String JavaDoc name, String JavaDoc text) {
24     name_ = name ;
25     value_ = text;
26     isCheck_ = false ;
27   }
28
29   final public String JavaDoc getValue() { return value_ ; }
30
31   final public UICheckBox setValue(String JavaDoc s) {
32     value_ = s ;
33     return this ;
34   }
35
36   final public boolean getSelect() { return isCheck_ ; }
37   final public UICheckBox setSelect(boolean b) {
38     isCheck_ = b ;
39     return this ;
40   }
41
42   public void decode(FacesContext context) {
43     if (!editable_ || readonly_) return ;
44     Map JavaDoc paramMap = context.getExternalContext().getRequestParameterMap() ;
45     String JavaDoc value = (String JavaDoc) paramMap.get(name_) ;
46     if (value == null) {
47       isCheck_ = false ;
48     } else {
49       isCheck_ = true ;
50     }
51   }
52
53   public void encodeBegin(FacesContext context) throws IOException JavaDoc {
54     ResponseWriter w = context.getResponseWriter() ;
55     String JavaDoc value = value_ ;
56     if (value == null) value = "" ;
57     String JavaDoc check = "" ;
58     if (isCheck_) check = " checked" ;
59     w.write("<input type='checkbox' name='"); w.write(name_); w.write("'") ;
60     w.write(" value='"); w.write(value); w.write("' ");
61     w.write(check) ;
62     if (!editable_ || readonly_) {
63       w.write(" readonly='readonly'");
64     }
65     w.write(" class='checkbox'/>") ;
66   }
67 }
68
69
Popular Tags