Hi,
I am new to Vaadin. It is wonderful framework to work on.
But I am stuck a problem please help me.
From a Main UI I am running a thread that after some time (5 sec) updates one row data in a table in main window.
I want it to happen asynchronously . But caling
application.getMainWindow().executeJavaScript(“javascript:vaadin.forceSync();”); /
application.getMainWindow().executeJavaScript(“vaadin.forceSync();”);
from thread table is not updated is happening.
But putting it as a link and firing that UI is rerendered.
Please find the code
Main Application Class
package com.ui;
import com.vaadin.Application;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Table;
import com.vaadin.ui.Window;
@SuppressWarnings("serial")
public class TestVaadinApplication extends Application {
public Panel mainPanel=null;
public AbsoluteLayout layout=null;
public Table urDBTable=null;
public Label syncLabel=null;
@Override
public void init() {
buildMainLayout();
startSeperateUIThread();
}
private void startSeperateUIThread() {
try{
new UIStateChangeThread(this).start();
}catch(Exception e){
e.printStackTrace();
}
}
private void buildMainLayout() {
setMainWindow(new Window("Test Vaadin Application"));
layout = new AbsoluteLayout();
layout.setSizeFull();
//layout.setImmediate(true);
setMainPanel(getMainPanelComponent());
layout.addComponent(getMainPanel(),"top:8%; left:25%;");
setSyncLabel(new Label(
"<a href=\"javascript:vaadin.forceSync();\">javascript: vaadin.forceSync();</a>",
Label.CONTENT_XHTML));
getMainWindow().setContent(layout);
}
private Panel getMainPanelComponent() {
final Panel panel=new Panel("Server Status");
panel.setHeight("700px");
panel.setWidth("890px");
panel.setScrollable(false);
//panel.setImmediate(true);
panel.addComponent(getTableGridStructureForDBInfo());
return panel;
}
private GridLayout getTableGridStructureForDBInfo() {
GridLayout grid=new GridLayout(1,2);
grid.setSpacing(false);
grid.setWidth("800px");
grid.setHeight("325px");
//grid.setImmediate(true);
Label urDBLabel = new Label("<h1>UR DB INFORMATION</h1>");
urDBLabel.setContentMode(Label.CONTENT_XHTML);
setUrDBTable(getURDBTable());
grid.addComponent(urDBLabel,0,0);
grid.addComponent(getUrDBTable(), 0,1);
return grid;
}
private Table getURDBTable() {
Table table = new Table();
//table.setImmediate(true);
table.addContainerProperty("Parameters",String.class,null);
table.addContainerProperty("Value",Label.class,null);
//table.addContainerProperty("Button",Button.class,null);
table.addItem(new Object[]{"Database Server Name:","localhost:50001"},new Integer(1));
table.addItem(new Object[]{"Schema Name :","UR;"},new Integer(2));
table.addItem(new Object[]{"Database Name :","UR_DEV"},new Integer(3));
table.addItem(new Object[]{"Datasource Name :","superPnrDB2DS "},new Integer(4));
table.addItem(new Object[]{"Available DB Connections :","50"},new Integer(5));
Label activeOrInactiveLabel=new Label("<b style=\"color: #009933\">ACTIVE</b>",Label.CONTENT_XHTML);
table.addItem(new Object[]{"Database Status :",activeOrInactiveLabel},new Integer(6));
table.setHeight("210px");
table.setWidth("400px");
table.setEditable(false);
table.setColumnReorderingAllowed(false);
table.setColumnCollapsingAllowed(false);
return table;
}
public Panel getMainPanel() {
return mainPanel;
}
public void setMainPanel(Panel mainPanel) {
this.mainPanel = mainPanel;
}
public AbsoluteLayout getLayout() {
return layout;
}
public void setLayout(AbsoluteLayout layout) {
this.layout = layout;
}
public Table getUrDBTable() {
return urDBTable;
}
public void setUrDBTable(Table urDBTable) {
this.urDBTable = urDBTable;
}
public Label getSyncLabel() {
return syncLabel;
}
public void setSyncLabel(Label syncLabel) {
this.syncLabel = syncLabel;
}
}
Thread code
package com.ui;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.ui.Table;
public class UIStateChangeThread extends Thread {
private TestVaadinApplication application;
public UIStateChangeThread(TestVaadinApplication application) {
this.application=application;
}
@Override
public void run(){
try{
Thread.sleep(5000);
Table urDBTable = this.application.getUrDBTable();
Item item = urDBTable.getItem(new Integer(1));
Property itemProperty = item.getItemProperty("Parameters");
itemProperty.setValue("Indraneel");
urDBTable.requestRepaint();
application.getMainWindow().executeJavaScript("javascript:vaadin.forceSync();");
}catch (Exception e) {
e.printStackTrace();
}
}
}
Please help me ASAP I need it urgent