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

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Tue Feb 19 07:23:34 EST 2008


Author: abelevich
Date: 2008-02-19 07:23:34 -0500 (Tue, 19 Feb 2008)
New Revision: 6158

Modified:
   trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
Log:
code refactoring for inplaceSelect needs 

Modified: trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
===================================================================
--- trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java	2008-02-19 11:55:26 UTC (rev 6157)
+++ trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java	2008-02-19 12:23:34 UTC (rev 6158)
@@ -37,10 +37,11 @@
 public class ComboBoxBaseRenderer extends HeaderResourcesRendererBase {
 	
 	private ArrayList <String> valuesList = null;
+	private final String RICH_COMBOBOX_ITEM_CLASSES = "rich-combobox-item rich-combobox-item-normal";
 	private static Log logger = LogFactory.getLog(ComboBoxBaseRenderer.class);
 		
 	
-	protected Class<UIComboBox>  getComponentClass() {
+	protected Class<? extends UIComponent>  getComponentClass() {
 		return UIComboBox.class;
 	}
 	
@@ -89,14 +90,14 @@
 				for (Iterator iterator = ((Collection)suggestionValues).iterator(); iterator.hasNext();) {
 					String value = getConvertedStringValue(context, comboBox, iterator.next()) ;
 					valuesList.add(value);
-					encodeSuggestion(writer, comboBox, value);
+					encodeSuggestion(writer, comboBox, value, RICH_COMBOBOX_ITEM_CLASSES);
 				}			
 			} else if (suggestionValues.getClass().isArray()) {
 				Object [] suggestions  = (Object [])suggestionValues; 
 				for (int i = 0; i < suggestions.length; i++) {
 					String value = getConvertedStringValue(context, comboBox, suggestions[i]);
 					valuesList.add(value);
-					encodeSuggestion(writer, comboBox, value );
+					encodeSuggestion(writer, comboBox, value, RICH_COMBOBOX_ITEM_CLASSES );
 				}				
 			} else {
 				throw new IllegalArgumentException("suggestionValues should be Collection or array");
@@ -110,22 +111,30 @@
 				SelectItem selectItem = iterator.next();
 				String value = getConvertedStringValue(context, comboBox, selectItem.getValue());
 				valuesList.add(value);
-				encodeSuggestion(writer, comboBox, value);
+				encodeSuggestion(writer, comboBox, value, RICH_COMBOBOX_ITEM_CLASSES);
 			}
 		}
 	}
 	
 	@Override
 	public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue)	throws ConverterException {
+		UIComboBox comboBox = null;
+		Converter converter = null;
+		
+		if(component instanceof UIComboBox) {
+			comboBox = (UIComboBox)component;
+			converter = comboBox.getConverter();
+		}
+		
+		return getConvertedValue(context, component, submittedValue, converter);
+	}
+	
+	public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue, Converter converter) {
 		Object convertedValue = null;
-		UIComboBox comboBox = null;
 		String newValue = (String)submittedValue;
+
+		ValueExpression valueExpression = component.getValueExpression("value");
 		
-		comboBox = (UIComboBox)component;
-			
-		Converter converter = comboBox.getConverter();
-		ValueExpression valueExpression = component.getValueExpression("value");
-			
 		if (converter == null) {
 			if (valueExpression != null) {
 				Class valueType = valueExpression.getType(context.getELContext());
@@ -140,7 +149,6 @@
 						throw new ConverterException(Messages.getMessage(Messages.NO_CONVERTER_FOUND_ERROR, valueType.getName()));
 					}
 				}
-				
 			}
 		}
 		
@@ -150,11 +158,20 @@
 			convertedValue = newValue;
 		}
 		return convertedValue;
+		
+		
 	}
 	
-	protected String getConvertedStringValue(FacesContext context, UIComboBox comboBox, Object value) {
-		Converter converter =  comboBox.getConverter();
-		
+	protected String getConvertedStringValue(FacesContext context, UIComponent component, Object value) {
+		Converter converter = null;
+		if (component instanceof UIComboBox) {
+			UIComboBox comboBox = (UIComboBox)component; 
+			converter =  comboBox.getConverter();
+		}
+		return getConvertedStringValue(context, component, value, converter);
+	}
+	
+	protected String getConvertedStringValue(FacesContext context, UIComponent component, Object value, Converter converter) {
 		if (converter == null) {
 			if (value == null) {
 				return "";
@@ -171,12 +188,12 @@
 				return value.toString();
 			}
 		}
-		return converter.getAsString(context, comboBox, value);		
+		return converter.getAsString(context, component, value);		
 	}
 	
-	public void encodeSuggestion(ResponseWriter writer, UIComboBox comboBox, String value) throws IOException{
-		writer.startElement(HTML.DIV_ELEM, comboBox);
-		writer.writeAttribute(HTML.class_ATTRIBUTE, "rich-combobox-item rich-combobox-item-normal", null);
+	public void encodeSuggestion(ResponseWriter writer, UIComponent component, String value, String classes) throws IOException{
+		writer.startElement(HTML.DIV_ELEM, component);
+		writer.writeAttribute(HTML.class_ATTRIBUTE, classes, null);
 		writer.write(value);
 		writer.endElement(HTML.DIV_ELEM);
 	}




More information about the richfaces-svn-commits mailing list