简体   繁体   English

GWT-建议框侦听器不起作用

[英]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). 当前功能正在(从模糊框中通过textInput)在从提示框中记录整个值之前进行验证,因此没有通过验证(应通过验证)。

Here is what i tried right below where i implement the suggestbox in the TextInput page: 这是我在下面在TextInput页面中实现意见箱的地方尝试的操作:

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. 永远不会达到断点。

Then take a look at ValueBoxBase. 然后看一下ValueBoxBase。

You will pass your own instance to the constructor of the SuggestBox 您将把自己的实例传递给SuggestBox的构造函数

public SuggestBox(SuggestOracle oracle, ValueBoxBase box) 公共的SuggestBox(建议Oracle oracle,ValueBoxBase框)

TextBox is a subclass of ValueBoxBase, and it has ClickListeners so you have the choice between: TextBox是ValueBoxBase的子类,它具有ClickListeners,因此您可以在以下选项之间进行选择:

  1. Create your TextBox outside and add it listeners, then pass it to the constructor SuggestBox(SuggestOracle oracle, ValueBoxBase box) 在外部创建您的TextBox并将其添加到侦听器,然后将其传递给构造函数RecommendationBox(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 重写SuggestBox,并使构造函数使用“更好的” ValueBoxBase(例如,TextBox),并将侦听器方法添加到您的实现中

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);

You could also use the advanced suggest box https://code.google.com/p/advanced-suggest-select-box/ 您还可以使用高级建议框https://code.google.com/p/advanced-suggest-select-box/

which gives you the control over the events: you can override valueSelected() or valueTyped() and decide whether to validate it or not. 这使您可以控制事件:可以覆盖valueSelected()或valueTyped()并决定是否对其进行验证。

The demo of the lib is here http://1vu-widgets.appspot.com/IntoGwt.html lib的演示在这里http://1vu-widgets.appspot.com/IntoGwt.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM