Hi all!
I am trying to simulate event that user is writing new value in combobox and then opens the list with mathcing data source values.
TextChangeListener tcl = new TextChangeListener() {
public void textChange(TextChangeEvent event) {
if (getFocusedChange()) {
setFocusedChange(false);
if (getId() != null) {
if (event.getText().length() > 0) {
String actualSeq = event.getText().substring(event.getText().length() - 1, event.getText().length());
JavaScript.getCurrent().execute("document.getElementById('" + getId() + "').firstChild.value='" + actualSeq + "'");
//Not working :(
DisComboBox.this.fireEvent(event);
}
} else {
log.log(Level.INFO, "DisComboBox component does not have ID !");
}
}
}
};
With .js i am changing the text field value from old to new. but list is showing empty if i type on keyboard the next symbol from word then list shows, how to simulate keyboard input on ComboBox filter thet after JavaScript execute user will see filtered list?
All code:
[code]
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.disnet.ui.panels.healthinsurance.myLog;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.event.FieldEvents.FocusListener;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.JavaScript;
@SuppressWarnings(“serial”)
public class MyComboBox extends ComboBox {
private Boolean focusedChange = false;
public myLog mylog = myLog.getInstance();
private static Logger log = Logger.getLogger(MyComboBox.class.getName());
@Override
public void changeVariables(Object source, Map<String, Object> variables) {
if (variables.containsKey("filter")) {
final String text = variables.get("filter").toString();
fireEvent(new TextChangeEvent(this) {
@Override
public String getText() {
return text;
}
@Override
public int getCursorPosition() {
return text.length();
}
});
}
super.changeVariables(source, variables);
}
public void addListener(TextChangeListener listener) {
addListener(TextChangeListener.EVENT_ID, TextChangeEvent.class, listener, TextChangeListener.EVENT_METHOD);
}
public void removeListener(TextChangeListener listener) {
removeListener(TextChangeListener.EVENT_ID, TextChangeEvent.class, listener);
}
public MyComboBox() {
super();
init();
}
public MyComboBox(String caption) {
super(caption);
init();
}
private void init() {
this.setImmediate(true);
this.addFocusListener(new FocusListener() {
public void focus(FocusEvent event) {
if (MyComboBox.this.getValue() != null) {
setFocusedChange(true);
}
}
});
this.addListener(tcl);
this.addBlurListener(new BlurListener() {
public void blur(BlurEvent event) {
setFocusedChange(false);
}
});
}
TextChangeListener tcl = new TextChangeListener() {
public void textChange(TextChangeEvent event) {
if (getFocusedChange()) {
setFocusedChange(false);
if (getId() != null) {
if (event.getText().length() > 0) {
String actualSeq = event.getText().substring(event.getText().length() - 1, event.getText().length());
JavaScript.getCurrent().execute("document.getElementById('" + getId() + "').firstChild.value='" + actualSeq + "'");
MyComboBox.this.fireEvent(event);
}
} else {
log.log(Level.INFO, "MyComboBox component does not have ID !");
}
}
}
};
public Boolean getFocusedChange() {
return focusedChange;
}
public void setFocusedChange(Boolean focusedChange) {
this.focusedChange = focusedChange;
}
}
[/code]I tryed markAsDirty and utc but nothing helps …
Thanks for any tip!