KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > weather > component > UIGenericForm


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.portlets.weather.component;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.Map JavaDoc;
10
11 import javax.faces.component.UIComponent;
12 import javax.faces.context.FacesContext;
13 import org.exoplatform.faces.core.component.UIGrid;
14 import org.exoplatform.faces.core.event.ExoActionEvent;
15
16
17 /**
18  * Jul 16, 2004, 11:36:22 AM
19  * @author: F MORON
20  * @email: francois.moron@rd.francetelecom.com
21  **/

22
23 public class UIGenericForm extends UIGrid {
24     final public static String JavaDoc GENERIC_FORM_RENDERER = "GenericFormRenderer";
25
26     private ArrayList JavaDoc commandButtons_;
27     private boolean error_;
28     private String JavaDoc formName_;
29     private String JavaDoc method_;
30     private String JavaDoc formId_;
31
32     public UIGenericForm(String JavaDoc name, String JavaDoc method, String JavaDoc formId) {
33         commandButtons_ = new ArrayList JavaDoc(5);
34         formName_ = name;
35         method_ = method;
36         formId_ = formId;
37        if (formId_ == null) formId_ = name ;
38         setRendererType(GENERIC_FORM_RENDERER);
39         setId(name) ;
40     }
41
42     public UIGenericForm register(UICommandButton button) {
43         for (int i=0; i<commandButtons_.size(); i++) {
44             if (( (UICommandButton) commandButtons_.get(i) ).getName().equalsIgnoreCase(button.getName())) return this;
45         }
46         commandButtons_.add(button);
47         return this;
48     }
49
50     public boolean hasError() { return error_; }
51
52     public void setError(boolean b) { error_ = b; }
53
54     public String JavaDoc getFormName() { return formName_; }
55
56     public String JavaDoc getMethod() { return method_; }
57
58     public String JavaDoc getFormId() { return formId_; }
59
60     public void decode(FacesContext context) {
61         Map JavaDoc paramMap = context.getExternalContext().getRequestParameterMap() ;
62         for (int i=0; i < commandButtons_.size(); i++) {
63             String JavaDoc buttonName = ((UICommandButton)commandButtons_.get(i)).getName();
64           if(paramMap.containsKey(buttonName)) {
65             broadcast(new ExoActionEvent(this, buttonName, paramMap)) ;
66                 return;
67            }
68         }
69     }
70   
71     public void processDecodes(FacesContext context) {
72         error_ = false;
73         Map JavaDoc paramMap = context.getExternalContext().getRequestParameterMap();
74         String JavaDoc uicomponent = (String JavaDoc) paramMap.get(UICOMPONENT);
75         if (!getId().equals(uicomponent)) return;
76         List JavaDoc children = getChildren();
77         for (int i = 0; i < children.size(); i++) {
78           UIComponent child = (UIComponent) children.get(i);
79           child.processDecodes(context);
80         }
81         decode(context);
82     }
83 }
Popular Tags