GWT- Suggestbox侦听器无法正常工作 [英] GWT- Suggestbox listener not working

查看:152
本文介绍了GWT- Suggestbox侦听器无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要添加一个处理程序,当一个选择被点击时触发,然后验证该值。当前的功能正在验证(通过模糊上的textInput),直到整个值从提示框记录下来,因此没有通过验证(当它应该)。



这是我尝试在我实现了TextInput页面中的提示框的地方:

  public void onModuleLoad(){

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

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

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

另一个解决方案可以是在选择了promptbox时将焦点插入焦点上,那样可以实现同样的效果对我来说。



问题在于处理程序永远不会触发。

然后看看ValueBoxBase。


$ b

解决方案

$ b

您将自己的实例传递给SuggestBox的构造函数



public SuggestBox(SuggestOracle oracle,ValueBoxBase框)

TextBox是ValueBoxBase的子类,它有ClickListeners,因此您可以选择:


  1. 创建TextBox外部并添加它的监听器,然后将它传递给构造函数SuggestBox(SuggestOracle oracle,ValueBoxBase框)
  2. 重写SuggestBox并使构造函数采用更好的ValueBoxBase(例如TextBox)并添加监听器方法给你的实现

我试过这个例子,它可以工作

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


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.

解决方案

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

这篇关于GWT- Suggestbox侦听器无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆