Any way to attach arbitrary data to SuggestOracle.Request? Functionality seems limited...

78 views
Skip to first unread message

TimOnGmail

unread,
Jul 13, 2012, 4:36:57 PM7/13/12
to google-we...@googlegroups.com
Hey all...

I was trying to find a way to substitute my own subclass of SuggestOracle.Request in a SuggestBox implementation.  This seems impossible, as the creation of the Request object happens deep in the bowels of the SuggestBox framework.

This is a problem - basically, we have a case where we want to add a "Show More" line to a list of suggestions.  Eg:

[fred]
Fred1
Fred2
Fred3
Show More...

I can add the "Show More" as a Suggestion, and subclass Suggestion so that it contains the metadata identifying it as a "special" value.

However, when I click on it, the Request object that the SuggestBox framework creates is a plain one, with only a String query and an int limit.

What I'd *like* is for any associated metadata I've added to the Suggestion subclass to be included in the Request object that is generated; even a reference to the original Suggestion object would be fine.  But this data is not available, so all I get is the query and the limit, and nothing else.

Has anyone ever gotten SuggestBox to work the way I want?  Substitute the creation of the Request object with your own implementation/subclass?  It seems a no-brainer that this would be useful, but it's not possible so far as I can see.

- Tim

Thomas Broyer

unread,
Jul 13, 2012, 10:10:37 PM7/13/12
to google-we...@googlegroups.com
The "Show more…" use case is already covered by SuggestBox without resorting to hacks like returning a special Suggestion: use setMoreSuggestions(true) on the Response.

Rendering is then done by the SuggestionDisplay. The DefaultSuggestionDisplay ignores the info, but you can provide your own SuggestionDisplay. If you don't want to implement one from scratch, you can easily add the functionnality to DefaultSuggestionDisplay: override decorateSuggestionList to wrap the menu in a container where you add a "Show More" button and then override setMoreSuggestions to show/hide the button. Alternately, but a bit hackish, you can simply get a handle on the widget in decorateSuggestionList and cast to a Menu widget, and in setMoreSuggestions dynamically add a "Show More" MenuItem to the menu.
The way you handle the click on "ShowMore" is up to you. You could e.g. create a Request with a different "limit", call your SuggestOracle and then call showSuggestions of your SuggestionDisplay with the result.

TimOnGmail

unread,
Jul 16, 2012, 1:30:23 AM7/16/12
to google-we...@googlegroups.com
Thanks for the - ahem - Suggestion, Thomas. :-)

I hadn't known about this functionality; the problem with it, in the codebase I'm working in, is that there is no standard among service calls (and the actual code doing the database queries within some EJBs) about how many rows of data are to be returned.  We have a requirement for a "Show more..." suggestion, but also for a "There are too many rows to display, please refine your query" suggestion.  Neither suggestion can be driven by the server side, it has to be the GUI telling the server "This is a request for my concept of the base limit of suggestions" and "This is a request for my concept of the MAX limit of suggestions".  The BASE and MAX values will differ in different locations in the GUI, even though they might be making the same back-end call.

Thus, the GUI has to tell the server "I want 10 suggestions, and that is the base request amount"; when "Show more..." is clicked, it has to tell the server "I want 20 suggestions, and that is the max request amount".  It also needs to tell the server "Actually query for BASE+X, but only return BASE suggestions".

I have gotten this to work on the GUI side by creating an extended SuggestBox class that modifies it's own limit, and keeps track of if it just requested the BASE or MAX amounts.  The problem with this, still, is that the server doesn't know how many extra rows to query for.

So it would be nice to be able to pass some more information along with my SuggestOracle.Request (as well as the SuggestOracle.Response) that gives context to the SuggestBox, so our subclass SuggestBox can be used thoughout the GUI, with just BASE, MAX, and X parameters set.

Perhaps I'm missing something - hey, I've done it before :-) - but I still feel it would be lovely to be able to pass some more contextual information back and forth in the Request and Response objects somehow.  I've worked on this by wrapping the SuggestOracle.Request object in another object that contains this context (intercepted in requestSuggestions()), and subclassed SuggestOracle.Response to wrap this context on the way back.

If you can think of a better way of passing this extra context back and forth in a generalized way, however, I'd love to know about it.

- Tim
Reply all
Reply to author
Forward
0 new messages