user1042147
user1042147

Reputation: 21

How Do I Use GWT As An External Component Engine?

For example, suppose I want to show a CellTable on my page. I want to define the rows & columns for this cell table in Javascript, provide a datasource, and then call a GWT method that would inject this cell table into the page and make an AJAX call to populate it with data.

It's important to note that my app already exists in its own war and deployed on the server - I want to deploy a another GWT app war and be able to call the javascript from my application and pass arguments to it (through javascript, for example) so that I can customize my CellTable columns and contents.

The problem is that a GWT application has one entry point and it doesn't accept any arguments - meaning I have to build my customized CellTable using some data that I plant on the html page and then extract inside onModuleLoad(). Doing this seems dumb as I would have to effectively code some kind of input/output language and parse it on my own, such as:

// entry point
public void onModuleLoad() {
    // Create a CellTable.
    CellTable<Data> table = new CellTable<Data>();
    // suppose we have a hidden element on the HTML page which has the column information for our cell table, i.e. <input type="hidden" id="SomeHiddenFieldValueWithInputs" value="Column1|Column2"/>

    RootPanel cellTableMetaData = RootPanel.get("SomeHiddenFieldValueWithInputs")   ; // suppose the value of this is Column 1|Column2
    String tableColumns = cellTableMetaData.getElement().getAttribute("value");
    String[] columns = tableColumns.split("|");
    for(String columnName:columns)
    {
        // Add a text column to show the name.
        TextColumn<Data> column = new TextColumn<Data>() {
            public String getValue(Data object) {
                return object.getValue(columnName); // this line doesn't even compile because columnName isn't visible here
            }
        };
        table.addColumn(column, columnName);

    }

    RootPanel.get("GwtCellTableContainerDiv").add(table);
}

Upvotes: 1

Views: 150

Answers (1)

Daniel Kurka
Daniel Kurka

Reputation: 7985

you need to build your second GWT App (the one having the custom CellTable) with the Cross Site Linker. With this linker GWT produces javascript that can be used in other javascript applications. ( http://code.google.com/intl/de-DE/webtoolkit/doc/latest/DevGuideOrganizingProjects.html#DevGuideModuleXml The section about Linkers)

To communicate with the CellTable App it has to export some Javascript functions with JSNI to be callable from javascript, here is an example: http://code.google.com/intl/de-DE/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html#calling

Upvotes: 1

Related Questions