What I am using:
Tomcat 7.0
Vaadin 7.0.0.Beta 10
The issue that I face:
I try to use javascript to simulate a button click on the client side (for some reason, I will use javascript to paste the clipboard information into a TextArea and submit it).
Server side code:
pasteTextArea = new TextArea();
pasteTextArea.setId(“txtPasteArea”);
layout.addComponent(pasteTextArea);
Button pasteDoneButton = new NativeButton(“Copy Value to Table”);
pasteDoneButton.setId(“btnPasteTriggerButton”);
pasteDoneButton.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
if (popupWindow.getParent() != null) {
// window is already showing
popupWindow.getUI().removeWindow(popupWindow);
table.pasteCells(pasteTextArea.getValue());
}
}
});
Javascript code:
var cb = document.getElementById(“txtPasteArea”);
cb.value=“$485,000 1475 Rose 185days” //this line just for testing the data
setTimeout(function() {
var btn = document.getElementById(“btnPasteTriggerButton”);
btn.click();
}, (1 * 1000));
The code works fine only when I use mouse to click the submit button. If I use javascript to click the button (btn.click();), the server side debug shows pasteTextArea.getValue() return empty (even the event ClickListener function runs correctly, I can debug it, just TextArea.getValue() is empty result).
I am not very sure whether it is a bug or I did it wrongly in the javascript (I have tried both Button and NativeButton, same issue).
##################UPDATE###################################
I just find out, that if I use javascript to set the value of the TextArea, the value will only pass to server if set the focus on another control before it is submit, I guess the vaadin use lose focus event to do a lot of pre-setup.
So now the below code works:
var cb = document.getElementById("txtPasteArea");
cb.focus();//Set focus on cb first.
cb.value="$485,000 1475 Rose 185days"
setTimeout(function() {
var btn = document.getElementById("btnPasteTriggerButton");
btn.focus(); //We need to set focus again to make cb lose focus, before we click the button, I think only in this way the textarea value will be notify to vaadin
btn.click();
}, (1 * 1000));