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

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Jan 4 09:37:59 EST 2008


Author: abelevich
Date: 2008-01-04 09:37:59 -0500 (Fri, 04 Jan 2008)
New Revision: 5139

Modified:
   trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
Log:
remove Collection.sort, suggestionValues now Collection of objects or array

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	2008-01-04 14:36:51 UTC (rev 5138)
+++ trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java	2008-01-04 14:37:59 UTC (rev 5139)
@@ -1,9 +1,7 @@
 package org.richfaces.renderkit;
 
 import java.io.IOException;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
+import java.util.Collection;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -19,56 +17,39 @@
 
 /**
  * @author Anton Belevich
- *
+ * @since 3.2.0
+ * ComboBox Base renderer implementation
+ *  	
  */
 public class ComboBoxBaseRenderer extends HeaderResourcesRendererBase {
-//
-//	private static final String INPUT = "_input";
-//	
-//	private static final String BUTTON = "_button";
-//	
-//	private static final String POPUP = "_popup";
 	
 	protected Class<UIComboBox>  getComponentClass() {
 		return UIComboBox.class;
 	}
 	
-	/*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);
-		
-	}*/
-	
 	public void encodeItems( FacesContext context, UIComponent component) throws IOException {
 		UIComboBox comboBox = (UIComboBox)component;
-		List <String> suggestionValues = comboBox.getSuggestionValues();
+		Object suggestionValues = comboBox.getSuggestionValues();
 		ResponseWriter writer = context.getResponseWriter();
-		//TODO we do not need to sort that
-		//TODO changing initial data source is a bad idea
-		//TODO should go after null check probably
-		Collections.sort(suggestionValues);
+		
 		if (suggestionValues != null) {
-			for (Iterator <String> iterator  = suggestionValues.iterator(); iterator.hasNext();) {
-				String suggestion = iterator .next();
+			Object [] items = null;
+		
+			if (suggestionValues instanceof Collection) {
+				Collection <String> itemsCollection = (Collection<String>)suggestionValues;
+				items = itemsCollection.toArray();
+			} else if (suggestionValues.getClass().isArray()) {
+				items = (Object []) suggestionValues;
+			} else {
+				throw new IllegalArgumentException("suggestionValues should be Collection of objects or array");
+			}
+			
+			for (int i = 0; i < items.length; i++) {
+				String suggestion = (String)items[i];
 				encodeSuggestion(writer, comboBox, suggestion);
 			}
 		}
+		
 	}
 	
 	protected void encodeSuggestion(ResponseWriter writer, UIComboBox comboBox, String value) throws IOException{
@@ -78,27 +59,9 @@
 		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");
-		String clientId  = comboBox.getClientId(context);
-		function.addParameter(clientId);
-		
-		Map<String, String> options = new HashMap<String, String>();
-		options.put("input", clientId + INPUT);
-		options.put("button", clientId + BUTTON);
-		options.put("popup", clientId + POPUP);
-		function.addParameter(options);
-		
-		return (function.toString() + ";");
-	}*/
-	
 	public String getItemsTextAsJSArray(FacesContext context, UIComponent component) {
 		UIComboBox comboBox = (UIComboBox)component;
-		List <String> suggestionValues = comboBox.getSuggestionValues();
-		
-		Collections.sort(suggestionValues); //FIXME
+		Object suggestionValues = comboBox.getSuggestionValues();
 		return ScriptUtils.toScript(suggestionValues);
 	}
 	




More information about the richfaces-svn-commits mailing list