我已经开发了一个复合小部件,比如在http://showrss.info/?cs=browse.I找到的下拉小部件,小部件关闭并打开正常,但我想关闭小部件,如果小部件外发生了点击事件(小部件上的模糊事件) )。目前我在窗口小部件上下沉Blur事件并覆盖onBrowserEvent方法。但我似乎没有捕获事件。 下面是我的代码片段。
public RichComboAutoSuggest(final Collection<String> data) {
initWidget(uiBinder.createAndBindUi(this));
this.data = data;
initComponents();
setUiListPanelData(listPanel);
//DOM.sinkEvents(RootPanel.get().getElement(), Event.ONCLICK);
this.sinkEvents(Event.ONCLICK|Event.ONBLUR);
this.addDomHandler(new FocusHandler() {
@Override public void onFocus(FocusEvent event) {
Window.alert("Blurred");
}
}, FocusEvent.getType());
searchBox.addKeyUpHandler(new KeyUpHandler() {
@Override public void onKeyUp(KeyUpEvent event) {
if (searchBox.getCursorPos() > 0) {
listPanel.clear();
noResults.setVisible(false);
String key = searchBox.getText();
List<String> returnedSearch = (List<String>) RichUtils.searchForMatches(data, key);
if (returnedSearch != null && !returnedSearch.isEmpty()) {
for (String string : returnedSearch) {
final Label l = new Label(string);
l.addClickHandler(new ClickHandler() {
@Override public void onClick(ClickEvent event) {
selectedValue.setText(l.getText());
dropShadowPanel.setVisible(false);
downArrow.setUrl("images/ddmenu_arrow.png");
resetFields();
listPanel.clear();
setUiListPanelData(listPanel);
}
});
listPanel.add(l);
}
}else{
listPanel.clear();
noResultsMsg.setText("No results found for \""+key+"\"");
noResults.setVisible(true);
}
}else{
listPanel.clear();
setUiListPanelData(listPanel);
}
}
});
@Override public void onBrowserEvent(Event event) {
int type = DOM.eventGetType(event);
switch (type) {
case Event.ONBLUR:
Window.alert("Blurred");
break;
default:
break;
}
super.onBrowserEvent(event);
}
}
答案 0 :(得分:0)
您需要添加BlurHandler
等代替FocusHandler。