You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/02/08 03:54:46 UTC
svn commit: r619748 -
/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/Autocomplete.java
Author: hlship
Date: Thu Feb 7 18:54:44 2008
New Revision: 619748
URL: http://svn.apache.org/viewvc?rev=619748&view=rev
Log:
TAPESTRY-2040: Allow subclasses of the Autocomplete mixin greater control over the JSON and markup rendered to the client
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/Autocomplete.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/Autocomplete.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/Autocomplete.java?rev=619748&r1=619747&r2=619748&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/Autocomplete.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/Autocomplete.java Thu Feb 7 18:54:44 2008
@@ -35,16 +35,17 @@
* A mixin for a text field that allows for autocompletion of text fields. This is based on Prototype's autocompleter
* control.
* <p/>
- * The mixin renders an (initially invisible) progress indicator after the field (it will also be after the error icon
- * most fields render). The progress indicator is made visible during the request to the server. The mixin then renders
- * a <div> that will be filled in on the client side with dynamically obtained selections.
+ * The mixin renders an (initially invisible) progress indicator after the field (it will also be after
+ * the error icon most fields render). The progress indicator is made visible during the request to the server.
+ * The mixin then renders a <div> that will be filled in on the client
+ * side with dynamically obtained selections.
* <p/>
- * Multiple selection on the client is enabled by binding the tokens parameter (however, the mixin doesn't help split
- * multiple selections up on the server, that is still your code's responsibility).
+ * Multiple selection on the client is enabled by binding the tokens parameter (however, the mixin doesn't
+ * help split multiple selections up on the server, that is still your code's responsibility).
* <p/>
- * The container is responsible for providing an event handler for event "providecompletions". The context will be the
- * partial input string sent from the client. The return value should be an array or list of completions, in
- * presentation order. I.e.
+ * The container is responsible for providing an event handler for event "providecompletions". The context
+ * will be the partial input string sent from the client. The return value should be an array or list of
+ * completions, in presentation order. I.e.
* <p/>
* <pre>
* String[] onProvideCompletionsFromMyField(String input)
@@ -99,15 +100,15 @@
/**
- * Overrides the default check frequency for determining whether to send a server request. The default is .4
- * seconds.
+ * Overrides the default check frequency for determining whether to send a server request.
+ * The default is .4 seconds.
*/
@Parameter(defaultPrefix = "literal")
private double _frequency;
/**
- * If given, then the autocompleter will support multiple input values, seperated by any of the individual
- * characters in the string.
+ * If given, then the autocompleter will support multiple input values, seperated by
+ * any of the individual characters in the string.
*/
@Parameter(defaultPrefix = "literal")
private String _tokens;
@@ -118,8 +119,8 @@
}
/**
- * Mixin afterRender phrase occurs after the component itself. This is where we write the <div> element and
- * the JavaScript.
+ * Mixin afterRender phrase occurs after the component itself. This is where we write the <div>
+ * element and the JavaScript.
*
* @param writer
*/
@@ -169,6 +170,9 @@
}
}
+ // Let subclasses do more.
+ configure(config);
+
_pageRenderSupport.addScript("new Ajax.Autocompleter('%s', '%s', '%s', %s);", id, menuId, link.toAbsoluteURI(),
config);
}
@@ -201,14 +205,38 @@
MarkupWriter writer = _factory.newMarkupWriter(contentType);
- // T4.1 has more flexibility, it can decorate the options with icons, etc.
- // But this will do for now. The Autocompleter widget will display
- // icons, but only the character text is stored into the target text field.
- // TODO: Support alternate return types allowing the event handler method to more precisely control the output.
+ generateResponseMarkup(writer, matchesHolder.get());
+
+ return new TextStreamResponse(contentType.getMimeType(), writer.toString());
+ }
+
+ /**
+ * Invoked to allow subclasses to further configure the parameters passed to the JavaScript
+ * Ajax.Autocompleter options. The values minChars, frequency and tokens my be pre-configured.
+ * Subclasses may override this method to configure additional features of the Ajax.Autocompleter.
+ * <p/>
+ * <p/>
+ * This implementation does nothing.
+ *
+ * @param config parameters object
+ */
+ protected void configure(JSONObject config)
+ {
+ }
+ /**
+ * Generates the markup response that will be returned to the client; this should be an
+ * <ul> element with nested <li> elements. Subclasses may override this to
+ * produce more involved markup (including images and CSS class attributes).
+ *
+ * @param writer to write the list to
+ * @param matches list of matching objects, each should be converted to a string
+ */
+ protected void generateResponseMarkup(MarkupWriter writer, List matches)
+ {
writer.element("ul");
- for (Object o : matchesHolder.get())
+ for (Object o : matches)
{
writer.element("li");
writer.write(o.toString());
@@ -216,7 +244,5 @@
}
writer.end(); // ul
-
- return new TextStreamResponse(contentType.getMimeType(), writer.toString());
}
}