1 5 package org.exoplatform.portlets.weather.component; 6 7 import java.util.ArrayList ; 8 import java.util.List ; 9 import java.util.Map ; 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 22 23 public class UIGenericForm extends UIGrid { 24 final public static String GENERIC_FORM_RENDERER = "GenericFormRenderer"; 25 26 private ArrayList commandButtons_; 27 private boolean error_; 28 private String formName_; 29 private String method_; 30 private String formId_; 31 32 public UIGenericForm(String name, String method, String formId) { 33 commandButtons_ = new ArrayList (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 getFormName() { return formName_; } 55 56 public String getMethod() { return method_; } 57 58 public String getFormId() { return formId_; } 59 60 public void decode(FacesContext context) { 61 Map paramMap = context.getExternalContext().getRequestParameterMap() ; 62 for (int i=0; i < commandButtons_.size(); i++) { 63 String 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 paramMap = context.getExternalContext().getRequestParameterMap(); 74 String uicomponent = (String ) paramMap.get(UICOMPONENT); 75 if (!getId().equals(uicomponent)) return; 76 List 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 |