[richfaces-svn-commits] JBoss Rich Faces SVN: r4996 - trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Sat Dec 22 12:04:03 EST 2007


Author: abelevich
Date: 2007-12-22 12:04:03 -0500 (Sat, 22 Dec 2007)
New Revision: 4996

Modified:
   trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
Log:
add script and items rendering 

Modified: trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
===================================================================
--- trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java	2007-12-22 17:03:30 UTC (rev 4995)
+++ trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java	2007-12-22 17:04:03 UTC (rev 4996)
@@ -2,6 +2,8 @@
 
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import javax.faces.component.UIComponent;
@@ -22,34 +24,54 @@
 	private static final String INPUT = "_input";
 	
 	private static final String BUTTON = "_button";
-
-	protected Class  getComponentClass() {
+	
+	private static final String POPUP = "_popup";
+	
+	protected Class<UIComboBox>  getComponentClass() {
 		return UIComboBox.class;
 	}
-
-	private String getScript(FacesContext context, UIComponent component){
+	
+	protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException {
+		UIComboBox comboBox = (UIComboBox)component;
+		String popupId = comboBox.getClientId(context) + POPUP;
+		writer.startElement(HTML.DIV_ELEM, comboBox);
+		writer.writeAttribute(HTML.id_ATTRIBUTE, popupId, null);
+		writer.writeAttribute(HTML.style_ATTRIBUTE, "display: none", null);
+		
+		List <String> suggestionValues = comboBox.getSuggestionValues();
+		if (suggestionValues != null) {
+			for (Iterator <String> iterator  = suggestionValues.iterator(); iterator.hasNext();) {
+				String suggestion = iterator .next();
+				encodeSuggestion(writer, comboBox, suggestion);
+			}
+		}
+		
+		writer.endElement(HTML.DIV_ELEM);
+		writer.startElement(HTML.SCRIPT_ELEM, component);
+        writer.writeText(encodeScript(context, component,popupId), "script");
+        writer.endElement(HTML.SCRIPT_ELEM);
+		
+	}
+	
+	protected void encodeSuggestion(ResponseWriter writer, UIComboBox comboBox, String value) throws IOException{
+		writer.startElement(HTML.DIV_ELEM, comboBox);
+		writer.write(value);
+		writer.endElement(HTML.DIV_ELEM);
+	}
+	
+	private String encodeScript(FacesContext context, UIComponent component, String popupId){
 		UIComboBox comboBox = (UIComboBox) component;
-		JSFunction function = new JSFunction("new Richfaces.Combobox");
+		
+		JSFunction function = new JSFunction("new Richfaces.ComboBox");
 		String clientId  = comboBox.getClientId(context);
 		function.addParameter(clientId);
-		Map options = new HashMap();
+		
+		Map<String, String> options = new HashMap<String, String>();
 		options.put("input", clientId + INPUT);
-		options.put("button", BUTTON);
+		options.put("button", clientId + BUTTON);
+		options.put("popup", clientId + POPUP);
 		function.addParameter(options);
-		return function.toString() ;
+		
+		return (function.toString() + ";");
 	}
-	
-	protected void doEncodeEnd(ResponseWriter writer, FacesContext context,	UIComponent component) throws IOException {
-	    super.doEncodeEnd(writer, context, component);
-	    writer.startElement(HTML.SCRIPT_ELEM, component);
-        writer.writeText(getScript(context, component), "script");
-        writer.endElement(HTML.SCRIPT_ELEM);
-
-	}
-	
-	protected void doEncodeChildren(ResponseWriter writer,
-			FacesContext context, UIComponent component) throws IOException {
-		// TODO Auto-generated method stub
-		super.doEncodeChildren(writer, context, component);
-	}
 }




More information about the richfaces-svn-commits mailing list