The API documentation has this to say on the subject:

"[...] To send back a DTO with each suggestion, extend the Suggestion
interface and define a getter method that has a return value of the
DTO's type. Define a class that implements this subinterface and use
it to encapsulate each suggestion.

To access a suggestion's DTO when the suggestion is selected, add a
SuggestionHandler to the SuggestBox (see SuggestBox's documentation
for more information). In the
SuggestionHandler.onSuggestionSelected(SuggestionEvent event) method,
obtain the selected Suggestion object from the SuggestionEvent object,
and downcast the Suggestion object to the subinterface. Then, acces
the DTO using the DTO getter method that was defined on the
subinterface."

See 
http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/SuggestOracle.Suggestion.html

(the 1.6 version is similar, but with the new event model)

So the endorsed solution is to extend and cast. Fair enough. This
probably dates from pre-1.5, and it was good enough for then. But is
there a reason not to parameterize SuggestBox with <T extends
Suggestion> (and SuggestOracle<T>, SelectionEvent<T>, etc.) now that
that's an option? Or perhaps make Suggestion implement HasValue<T>? I
have an application that uses many SuggestBoxes and many different
Suggestion subclasses and this would simplify things (and eliminate
much type-casting).

Any thoughts on this? Horrible side effects that I'm missing?

- Isaac

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to