myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r546479 - /myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/inputsuggestajax/InputSuggestAjaxRenderer.java
Date Tue, 12 Jun 2007 13:34:14 GMT
Author: imario
Date: Tue Jun 12 06:34:13 2007
New Revision: 546479

URL: http://svn.apache.org/viewvc?view=rev&rev=546479
Log:
Starting with the patch supplied at TOMAHAWK-258 the inputSuggestAjax stopped working with
itemLabelMethod.
The reason is, that now two input elements with the same id are rendered.

In case of label usage, fake the component id when going to render the input element for input.
Also set the SubmittedValue to get the label rendered as value instead of the value object.

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=546479&r1=546478&r2=546479
==============================================================================
--- 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 Jun 12 06:34:13 2007
@@ -87,7 +87,7 @@
         String hiddenInputValue = null;
 
         String mainComponentRenderedValue = null;
-        
+
 		/* check if the user supplied a label method */
 		if (inputSuggestAjax.getItemLabelMethod() == null)
 		{
@@ -111,7 +111,7 @@
             }
         }
 
-        String placeHolderId = context.getViewRoot().createUniqueId(); 
+        String placeHolderId = context.getViewRoot().createUniqueId();
         out.startElement(HTML.DIV_ELEM, component);
         out.writeAttribute(HTML.ID_ATTR, placeHolderId , null);
         if(inputSuggestAjax.getStyle() != null)
@@ -123,15 +123,43 @@
             out.writeAttribute(HTML.CLASS_ATTR, inputSuggestAjax.getStyleClass(), null);
         }
         out.endElement(HTML.DIV_ELEM);
-        super.encodeEnd(context, inputSuggestAjax);
 
-        String inputSuggestComponentVar = DojoUtils.calculateWidgetVarName(placeHolderId);
+		String textInputId = inputSuggestAjax.getId();
+		if (label != null)
+		{
+			// whe have a label method and thus a hidden input field holding the real value
+			// now fake the component id to have the rendered input component use another id
+			// than the one we render later for the real value
+			String oriId = inputSuggestAjax.getId();
+			try
+			{
+				// fake the label
+				inputSuggestAjax.setId(oriId + "_fake");
+
+				// fake a submitted value so we have it rendered
+				inputSuggestAjax.setSubmittedValue(label);
+
+				textInputId = inputSuggestAjax.getClientId(context);
+				super.encodeEnd(context, inputSuggestAjax);
+			}
+			finally
+			{
+				inputSuggestAjax.setSubmittedValue(null);
+				inputSuggestAjax.setId(oriId);
+			}
+		}
+		else
+		{
+			super.encodeEnd(context, inputSuggestAjax);
+		}
+
+		String inputSuggestComponentVar = DojoUtils.calculateWidgetVarName(placeHolderId);
 
         Map attributes = new HashedMap();
 
         attributes.put("dataUrl", ajaxUrl);
         attributes.put("mode", "remote");
-        attributes.put("textInputId", clientId);
+        attributes.put("textInputId", textInputId);
 
         String autoComplete = inputSuggestAjax.getAutoComplete().booleanValue()?"true":"false";
         attributes.put("autoComplete", autoComplete);
@@ -191,7 +219,7 @@
 		{
 			return converter;
 		}
-		
+
 		Class type = inputSuggestAjax.getValueBinding("value").getType(context);
 		if (type != null)
 		{



Mime
View raw message