You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2006/10/31 21:25:14 UTC
svn commit: r469639 -
/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/InputSuggestAjaxRenderer.java
Author: imario
Date: Tue Oct 31 12:25:13 2006
New Revision: 469639
URL: http://svn.apache.org/viewvc?view=rev&rev=469639
Log:
changed how to determine if the value/label stuff should be used
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/InputSuggestAjaxRenderer.java
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/InputSuggestAjaxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/InputSuggestAjaxRenderer.java?view=diff&rev=469639&r1=469638&r2=469639
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/InputSuggestAjaxRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/InputSuggestAjaxRenderer.java Tue Oct 31 12:25:13 2006
@@ -89,34 +89,33 @@
String idToRender = null;
- if (valueObject instanceof String)
- {
- valueToRender = (String) valueObject;
-
- idToRender = clientId;
- }
- else if (valueObject == null)
- {
- valueToRender = "";
-
- idToRender = clientId;
- }
- else
+ /* check if the user supplied a label method */
+ if (inputSuggestAjax.getItemLabelMethod() == null)
+ {
+ if (valueObject instanceof String)
+ {
+ valueToRender = (String) valueObject;
+
+ idToRender = clientId;
+ }
+ else if (valueObject == null)
+ {
+ valueToRender = "";
+
+ idToRender = clientId;
+ }
+ }
+ else
{
MethodBinding labelMethod = inputSuggestAjax.getItemLabelMethod();
if (labelMethod != null)
{
- Converter converter = inputSuggestAjax.getConverter();
-
- if (converter == null)
- {
- throw new IllegalStateException("There must be a registered converter if " +
- "attribute \"labelMethod\" is used");
- }
+ Converter converter = getRequiredConverter(context, inputSuggestAjax);
label = (String) labelMethod.invoke(context, new Object[]{valueObject});
- value = converter.getAsString(context, inputSuggestAjax, valueObject);
+
+ value = converter.getAsString(context, inputSuggestAjax, valueObject);
idToRender = clientId + "_valueFake";
}
@@ -192,7 +191,29 @@
}
}
- public void encodeAjax(FacesContext context, UIComponent uiComponent)
+ protected Converter getRequiredConverter(FacesContext context, InputSuggestAjax inputSuggestAjax)
+ {
+ Converter converter = inputSuggestAjax.getConverter();
+ if (converter != null)
+ {
+ return converter;
+ }
+
+ Class type = inputSuggestAjax.getValueBinding("value").getType(context);
+ if (type != null)
+ {
+ converter = context.getApplication().createConverter(type);
+ if (converter != null)
+ {
+ return converter;
+ }
+ }
+
+ throw new IllegalStateException("There must be a converter if " +
+ "attribute \"labelMethod\" is used");
+ }
+
+ public void encodeAjax(FacesContext context, UIComponent uiComponent)
throws IOException
{
InputSuggestAjax inputSuggestAjax = (InputSuggestAjax) uiComponent;
@@ -207,12 +228,7 @@
if (labelMethod != null)
{
- Converter converter = inputSuggestAjax.getConverter();
-
- if (converter == null)
- {
- throw new IllegalStateException("There must be a registered converter if attribute \"labelMethod\" is used");
- }
+ Converter converter = getRequiredConverter(context, inputSuggestAjax);
for (Iterator iterator = suggesteds.iterator(); iterator.hasNext();)
{