Author: abelevich
Date: 2008-01-10 09:29:50 -0500 (Thu, 10 Jan 2008)
New Revision: 5265
Modified:
trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
Log:
add decode, getConvertedValue method impl
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-10
14:11:05 UTC (rev 5264)
+++
trunk/sandbox/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java 2008-01-10
14:29:50 UTC (rev 5265)
@@ -5,20 +5,28 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
+import javax.faces.component.ValueHolder;
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;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.ajax4jsf.util.InputUtils;
import org.ajax4jsf.util.SelectUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.richfaces.component.UIComboBox;
/**
@@ -30,11 +38,46 @@
public class ComboBoxBaseRenderer extends HeaderResourcesRendererBase {
private ArrayList <String> valuesList = null;
+ private static Log logger = LogFactory.getLog(ComboBoxBaseRenderer.class);
+
protected Class<UIComboBox> getComponentClass() {
return UIComboBox.class;
}
+ protected void doDecode(FacesContext context, UIComponent component) {
+ UIComboBox comboBox = null;
+
+ if (component instanceof UIComboBox) {
+ comboBox = (UIComboBox)component;
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("No decoding necessary since the component "
+ + component.getId() + " is not an instance or a sub class of
UIComboBox");
+ }
+ return;
+ }
+
+ if (InputUtils.isDisabled(comboBox) || InputUtils.isReadOnly(comboBox)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("No decoding necessary since the component "
+ + component.getId() + " is disabled");
+ }
+ }
+
+ String clientId = component.getClientId(context);
+ if (clientId == null) {
+ throw new NullPointerException("client id is null in component " +
comboBox.getClientId(context));
+ }
+
+ clientId = "comboboxField" + clientId;
+ Map request = context.getExternalContext().getRequestParameterMap();
+ if (request.containsKey(clientId)) {
+ String newValue = (String)request.get(clientId);
+ comboBox.setSubmittedValue(newValue);
+ }
+ }
+
public void encodeItems( FacesContext context, UIComponent component) throws IOException
{
UIComboBox comboBox = (UIComboBox)component;
Object suggestionValues = comboBox.getSuggestionValues();
@@ -71,7 +114,43 @@
encodeSuggestion(writer, comboBox, value);
}
}
+ }
+ @Override
+ public Object getConvertedValue(FacesContext context, UIComponent component, Object
submittedValue) throws ConverterException {
+ Object convertedValue = null;
+ UIComboBox comboBox = null;
+ String newValue = (String)submittedValue;
+
+ comboBox = (UIComboBox)component;
+
+ Converter converter = comboBox.getConverter();
+ 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, UIComboBox comboBox,
Object value) {
@@ -87,7 +166,6 @@
throw new IllegalArgumentException(message);
}
}
-
return converter.getAsString(context, comboBox, value);
}
@@ -121,12 +199,6 @@
result = function;
}
}
-
return ScriptUtils.toScript(result);
}
-
- @Override
- public boolean getRendersChildren() {
- return super.getRendersChildren();
- }
}
Show replies by date