开发者

how to keep view "humble" -using SuggestBox with special Oracle and Suggestion

i learned how to implement my own SuggestionOracle("AuSuggestOracle") and own Suggestions("AuMultiWordSuggestion"). In my case the suggestion object is constructed with a DTO. On a selection event i need this dto (or some fields of it) to react appropriate. I implemented a widget containing 3 suggest boxes with this special oracle and some logic between them. Now i want to apply MVP pattern - split this widget in presenter and view. At the moment the presenters display interface look like that:

    public interface Display {
            HasSelectionHandlers<Suggestion> getFedLand();
            HasSelectionHandlers<Suggestion> getCounty();
            HasSelectionHandlers<Suggestion> getCommunity();
            AuSuggestOracle getFedLandOracle();
            AuSuggestOracle getCountyOracle();
            AuSuggestOracle getCommunityOracle();
            void clearCounty();
            void clearCommunity();
            void activateForm();
            Widget asWidget();
    }

the problem is the implicit knowledge about my model in methods returning "AuSuggestOracle". so my question is how to get the view/ interface "humble". in my case the displayed suggestion-strings 开发者_StackOverfloware ambiguous and i need at least the "id" of a selected item to know what DTObject is selected.


The way I got around this is by leaving out the getters for the Oracle since once my presenter sets it my view doesn't need any information about it. So, my interface looked like this:

public interface Display {
    ...

    void setSuggestionOracle(SuggestOracle oracle);
    HasSelectionHandlers<SuggestOracle.Suggestion> getSelectionListener();
}

The problem I encountered was being able to add the suggestion to the SuggestBox after it was instantiated. To get around this, I initialized with a blank SuggestBox and then removed it from the view, updated in, and inserted it back into position.

After that, you can write your handler (in the presenter) to check if the suggestion is an instance of your custom suggestion and your presenter can handle the selection and push the relevant information back down to your view.

By doing this, all your view knows is that it will be taking generic suggestions for something, and that at some later time it will be updating with information (which will be as a result of the suggestion, but the view is to 'humble' to know that).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜