Author: abelevich
Date: 2008-03-20 10:22:10 -0400 (Thu, 20 Mar 2008)
New Revision: 6997
Modified:
trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
Log:
move converter methods to the InputUtils.
Modified:
trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
===================================================================
---
trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java 2008-03-20
14:12:43 UTC (rev 6996)
+++
trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java 2008-03-20
14:22:10 UTC (rev 6997)
@@ -7,15 +7,12 @@
import java.util.List;
import java.util.Map;
-import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.model.SelectItem;
-import org.ajax4jsf.Messages;
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.javascript.ScriptString;
@@ -116,77 +113,13 @@
@Override
public Object getConvertedValue(FacesContext context, UIComponent component, Object
submittedValue) throws ConverterException {
- UIComboBox comboBox = null;
- Converter converter = null;
+ return InputUtils.getConvertedValue(context, component, submittedValue);
- 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;
- String newValue = (String) submittedValue;
-
- ValueExpression valueExpression = component.getValueExpression("value");
-
- if (converter == null) {
- if (valueExpression != null) {
- Class valueType = valueExpression.getType(context.getELContext());
- if (valueType == null || String.class.equals(valueType) ||
Object.class.equals(valueType)) {
- if (logger.isDebugEnabled()) {
- logger.debug("No conversion necessary for value " + newValue + " of
component " + component.getClientId(context));
- }
- } else {
- converter = context.getApplication().createConverter(valueType);
- if (converter == null) {
- throw new ConverterException(Messages.getMessage(Messages.NO_CONVERTER_FOUND_ERROR,
valueType.getName()));
- }
- }
- }
- }
-
- if (converter != null) {
- convertedValue = converter.getAsObject(context, component, newValue);
- } else {
- convertedValue = newValue;
- }
- return convertedValue;
-
- }
-
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);
+ return InputUtils.getConvertedStringValue(context, component, value);
}
- protected String getConvertedStringValue(FacesContext context, UIComponent component,
Object value, Converter converter) {
- if (converter == null) {
- if (value == null) {
- return "";
- } else if (value instanceof String) {
- return (String) value;
- }
-
- Class converterType = value.getClass();
- if (converterType != null) {
- converter = context.getApplication().createConverter(converterType);
- }
-
- if (converter == null) {
- return value.toString();
- }
- }
- return converter.getAsString(context, component, value);
- }
-
public void encodeSuggestion(ResponseWriter writer, UIComponent component, String
value, String classes) throws IOException {
writer.startElement(HTML.SPAN_ELEM, component);
writer.writeAttribute(HTML.class_ATTRIBUTE, classes, null);
Show replies by date