Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

java - GWT- Suggestbox listener not working

I need to add a handler that fires when a selection is CLICKED which will then validate the value. Current functionality is validating (through textInput on blur) right before the entire value is recorded from the suggestbox, thus not passing validation (when it should).

Here is what i tried right below where i implement the suggestbox in the TextInput page:

public void onModuleLoad() {

SuggestBox box = new SuggestBox(createListOracle(),myTextBox());

box.addSelectionHandler(new SelectionHandler<Suggestion>() {

    @Override
    public void onSelection(SelectionEvent<Suggestion> event) {
        Validate();
    }
});

another solution could be to insert the courser on focus when suggestbox is selected from, that would accomplish the same thing for me.

The problem is the handler is never firing. The break-point is never reached.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Then take a look at ValueBoxBase.

You will pass your own instance to the constructor of the SuggestBox

public SuggestBox(SuggestOracle oracle, ValueBoxBase box)

TextBox is a subclass of ValueBoxBase, and it has ClickListeners so you have the choice between:

  1. Create your TextBox outside and add it listeners, then pass it to the constructor SuggestBox(SuggestOracle oracle, ValueBoxBase box)
  2. Overriding SuggestBox and making the constructor take a "better" ValueBoxBase (for example TextBox) and add the listener methods to your implmentation

I tried this sample, it works

        TextBox suggestTextBox = new TextBox();
    suggestTextBox.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Window.alert("tada");
        }
    });
    SuggestOracle oracle = new MultiWordSuggestOracle(" ,");

    final SuggestBox nameField = new SuggestBox(oracle, suggestTextBox);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...