KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.List JavaDoc ;
9 import java.util.ResourceBundle JavaDoc;
10 import java.io.IOException JavaDoc ;
11 import javax.faces.context.FacesContext;
12 import javax.faces.context.ResponseWriter;
13 import org.exoplatform.commons.utils.ExpressionUtil;
14 import org.exoplatform.faces.core.Util;
15 import org.exoplatform.faces.core.component.model.*;
16
17 /**
18
19  * Wed, Dec 22, 2003 @ 23:14
20
21  * @author: Tuan Nguyen
22
23  * @email: tuan08@users.sourceforge.net
24
25  * @version: $Id: UISelectBox.java,v 1.6 2004/06/26 03:47:31 tuan08 Exp $
26
27  */

28 public class UISelectBox extends UIInput {
29   private String JavaDoc updateOnChangeAction_ ;
30   protected String JavaDoc value_ ;
31   private List JavaDoc options_ ;
32
33   public UISelectBox(String JavaDoc name, String JavaDoc value, List JavaDoc options) {
34     name_ = name ;
35     value_ = value;
36     options_ = options ;
37   }
38
39   final public String JavaDoc getValue() { return value_ ; }
40   final public UISelectBox setValue(String JavaDoc s) {
41     value_ = s ;
42     return this ;
43   }
44
45   final public String JavaDoc getUpdateOnChangeAction() { return updateOnChangeAction_ ; }
46   final public UISelectBox setUpdateOnChangeAction(String JavaDoc s) {
47     updateOnChangeAction_ = s ;
48     return this ;
49   }
50
51   final public List JavaDoc getOptions() { return options_ ; }
52
53   final public UISelectBox setOptions(List JavaDoc options) {
54     options_ = options ;
55     return this ;
56   }
57
58   public void decode(FacesContext context) {
59     if (!editable_ || readonly_) return ;
60     Map JavaDoc paramMap = context.getExternalContext().getRequestParameterMap() ;
61     String JavaDoc value = (String JavaDoc) paramMap.get(name_) ;
62     if (value != null) {
63       value_ = value ;
64     }
65   }
66
67   public void encodeBegin(FacesContext context) throws IOException JavaDoc {
68     ResponseWriter w = context.getResponseWriter() ;
69     ResourceBundle JavaDoc res = Util.getApplicationResourceBundle() ;
70     w.write("<select "); w.write("name='"); w.write(name_); w.write("'") ;
71     if (!editable_ || readonly_) {
72       w.write(" disabled='true'");
73     }
74     if(getClazz() != null) {
75       w.write(" class='"); w.write(getClazz()); w.write("'") ;
76     }
77     if(updateOnChangeAction_ != null) {
78       UISimpleForm uiForm = (UISimpleForm) getParent();
79       String JavaDoc formName = uiForm.getFormName() ;
80       w.write(" onchange=\"javascript:submit_"); w.write(formName); w.write("('") ;
81       w.write(updateOnChangeAction_); w.write("')\"") ;
82     }
83     w.write(">\n") ;
84     for(int i=0; i < options_.size(); i++) {
85       SelectItem si = (SelectItem) options_.get(i) ;
86       if (si.value_.equals(value_)) {
87         w.write("<option selected=\"selected\" value=\""); w.write(si.value_); w.write("\">");
88         w.write(ExpressionUtil.getExpressionValue(res,si.display_)); w.write("</option>\n");
89       } else {
90         w.write("<option value=\""); w.write(si.value_); w.write("\">");
91         w.write(ExpressionUtil.getExpressionValue(res,si.display_)); w.write("</option>\n");
92       }
93     }
94     w.write("</select>\n") ;
95   }
96 }
97
Popular Tags