Hi, all. I need to integrate light streamer with smart gwt. I tried to show existing static page in gwt with
// this page is hosted in the light streamer server
htmlPane.setContentsURL("http://localhost:8888/demos/HelloWorld/");
and it worked, but i don’t think this is the best approach.
I need to integrate the following code in smart gwt :
<html>
<head>
<title>Hello World with Lightstreamer</title>
<script language="JavaScript" src="LS/lscommons.js"></script>
<script language="JavaScript" src="LS/lspushpage.js"></script>
</head>
<body>
<div source="lightstreamer" table="hellotable" item="greetings" field="message">loading...</div>
<div source="lightstreamer" table="hellotable" item="greetings" field="timestamp">loading...</div>
<script>
var page = new PushPage();
page.onEngineCreation = function(engine) {
engine.connection.setAdapterName("HELLOWORLD");
engine.changeStatus("STREAMING");
}
page.bind();
page.createEngine("HelloWorldApp", "LS", "SHARE_SESSION");
var pushtable = new OverwriteTable(null, null, "MERGE");
page.addTable(pushtable, "hellotable");
</script>
</body>
</html>
This is the static page, that light streamer updates and i just set it in htmlPane.
In my first approach i just display the page, but i can’t acess the data that is updated.
I tried to use htmlPane.getChilderen() but no success. Coulde some one tell me how to translate the above page in smart gwt code, so i can access the “message” and “timestamp” values that come from light streamer.
How to get the children of HtmlFlow?
It seems that HtmlFlow is iframe that wraps the page passed with content url.
But flow.getDOM().getChildNodes() returns me empty list. How could i access some div within this iframe using flow.getDOM() ?
Well, that’s our client’s decision. They already have light streamer license for other products and want to use it in our product again. I managed to load html page from light streamer in gwt(using HtmlFlow) but it push the html page in iframe and i do not know how to access the page using dom. HtmlFlow has method getDOM().getOwnerDocument() … but i miss something! :(\
I successfully integrated lightstreamer with (smart) gwt. It is just one native js method. Here is a simple example of usage:
package ls.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.VLayout;
public class GwtLSIntegrationTest implements EntryPoint {
public void onModuleLoad() {
final VLayout main = new VLayout();
main.setHeight(600);
main.setWidth(1000);
final ListGrid grid = new ListGrid();
grid.setAutoFetchData(true);
grid.setHeight100();
grid.setWidth100();
final ListGridField field1 = new ListGridField("message", "message");
final ListGridField field2 = new ListGridField("timestamp", "timestamp");
grid.setFields(field1, field2);
main.addMember(grid);
// init
final ListGridRecord record = new ListGridRecord();
record.setAttribute("message", "loading...");
record.setAttribute("timestamp", "");
grid.addData(record);
final int index = grid.getRecordIndex(record);
RootPanel.get("nameFieldContainer").add(main);
final Button button = new Button("Start");
init(grid, record.getJsObj(), index);
button.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
SC.say(grid.getSelectedRecord().getAttributeAsString("message") + " " + grid.getSelectedRecord().getAttributeAsString("timestamp"));
}
});
main.addMember(button);
main.draw();
}
private static native void init(ListGrid grid, JavaScriptObject record, int index) /*-{
try {
var page = new $wnd.PushPage();
page.context.setDomain("localhost");
page.onEngineCreation = function(engine) {
engine.connection.setLSHost("localhost");
engine.connection.setLSPort(8888);
engine.connection.setAdapterName("HELLOWORLD");
engine.changeStatus("STREAMING");
}
page.bind();
page.createEngine("HelloWorldApp", "LS/", "SHARE_SESSION");
var schema = new Array("message","timestamp");
var group = new Array("greetings");
var nvt = new $wnd.NonVisualTable(group,schema,"MERGE");
nvt.setSnapshotRequired(true);
var c = 1;
nvt.onItemUpdate = function(item, itemUpdate, itemName) {
if (itemUpdate.isValueChanged("message")) {
var msg = itemUpdate.getNewValue("message");
var ts = itemUpdate.getNewValue("timestamp");
record["message"] = msg;
record["timestamp"] = ts;
var self = grid.@com.smartgwt.client.widgets.BaseWidget::getOrCreateJsObj()();
self.refreshRow(index);
}
}
page.addTable(nvt,"hellotable");
} catch(error) {
alert(error);
}
}-*/;
}
The tricky part (for non javascript dev or for me) was $wnd in front of the PushPage and NonVisialTable. If you don’t have $wnd you will get PushPage is not defined.
The next tricky thing is the same origin policy. I just added this in my gwt.xml file: