Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

Showcase Grid to Excel Not Working

$
0
0
Upgrading to SmartClient Version: v9.0p_2013-08-30/Enterprise Deployment (built 2013-08-30) using IE9.

Showcase example Grid to Excel does not work any longer - then it calls the dataSource.recordsAsText(records, settings) the following exception is generated:

Code:

17:51:19.908 [ERROR] [com.pci.gp.GP] Uncaught exception escaped
com.google.gwt.event.shared.UmbrellaException: Exception caught: (Error) @com.smartgwt.client.data.DataSource::recordsAsText([Lcom/smartgwt/client/data/Record;Lcom/smartgwt/client/data/TextExportSettings;)([Java object: [Lcom.smartgwt.client.widgets.grid.ListGridRecord;@1954013410, Java object: com.smartgwt.client.data.TextExportSettings@237110523]): Out of stack space
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
    at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:72)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
    at sun.reflect.GeneratedMethodAccessor79.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    at java.lang.Thread.run(Thread.java:722)
Caused by: com.google.gwt.core.client.JavaScriptException: (Error) @com.smartgwt.client.data.DataSource::recordsAsText([Lcom/smartgwt/client/data/Record;Lcom/smartgwt/client/data/TextExportSettings;)([Java object: [Lcom.smartgwt.client.widgets.grid.ListGridRecord;@1954013410, Java object: com.smartgwt.client.data.TextExportSettings@237110523]): Out of stack space
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.smartgwt.client.data.DataSource.recordsAsText(DataSource.java)
    at com.pci.gp.client.GP$MyDialog.<init>(GP.java:127)
    at com.pci.gp.client.GP.onClick(GP.java:135)
    at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:103)
    at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:1)
    at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
    at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
    at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
    at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
    at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:72)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
    at sun.reflect.GeneratedMethodAccessor79.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    at java.lang.Thread.run(Thread.java:722)

Here is the actual code I'm running - had to work ajust the code from the Showcase to make it work.

Code:

package com.pci.gp.client;

import java.util.ArrayList;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.TextExportSettings;
import com.smartgwt.client.data.fields.DataSourceBooleanField;
import com.smartgwt.client.data.fields.DataSourceDateField;
import com.smartgwt.client.data.fields.DataSourceFloatField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceLinkField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Autofit;
import com.smartgwt.client.types.EscapingMode;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.Dialog;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
import com.smartgwt.client.widgets.form.fields.TextAreaItem;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.grid.events.CellContextClickEvent;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.menu.Menu;
import com.smartgwt.client.widgets.menu.MenuItem;
import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;

public class GP implements EntryPoint, ClickHandler,
                com.smartgwt.client.widgets.menu.events.ClickHandler
{
        private ListGrid countryList;

        private class MyDialog extends Dialog implements

                        com.smartgwt.client.widgets.form.fields.events.ClickHandler
        {

                private DynamicForm form;

                private TextAreaItem textArea;

                public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event)
                {
                        this.removeItem(this.form);
                        this.markForDestroy();
                        this.hide();
                };

                public MyDialog()
                {

                        final int WIDTH = 525;
                        final int HEIGHT = 300;

                        final String GUIDANCE = "Press Ctrl-C (Command-C on Mac) or right click (Option-click on Mac) on the selected text to copy values, then paste into Excel.  Note that values in columns that are dates or numbers are correctly understood as dates and numbers in Excel.";

                        int[][] cells = countryList.getCellSelection().getSelectedCells();
                        if (cells == null || cells.length == 0)
                                return;

                        ArrayList<String> fieldNames = new ArrayList<String>();

                        int firstRow = cells[0][0];
                        for (int i = 0; i < cells.length; i++)
                        {
                                if (cells[i][0] != firstRow)
                                        break;
                                fieldNames.add(countryList.getFieldName(cells[i][1]));
                        }

                        TextExportSettings settings = new TextExportSettings();
                        settings.setFieldList(fieldNames.toArray(new String[0]));
                        settings.setFieldSeparator("\t");
                        settings.setEscapingMode(EscapingMode.DOUBLE);

                        StaticTextItem label = new StaticTextItem();
                        label.setName("label");
                        label.setShowTitle(false);
                        label.setValue(GUIDANCE);

                        TextAreaItem area = new TextAreaItem();
                        area.setName("textArea");
                        area.setShowTitle(false);
                        area.setCanEdit(true);
                        area.setHeight("*");
                        area.setWidth("*");
                        this.textArea = area;

                        ButtonItem button = new ButtonItem();
                        button.setName("done");
                        button.setAlign(Alignment.CENTER);
                        button.setTitle("Done");
                        button.addClickHandler(this);

                        DynamicForm form = new DynamicForm();
                        form.setNumCols(1);
                        form.setWidth(WIDTH);
                        form.setHeight(HEIGHT);
                        form.setAutoFocus(true);
                        form.setFields(new FormItem[] { label, this.textArea, button });
                        this.form = form;

                        this.setAutoSize(true);
                        this.setShowToolbar(false);
                        this.setCanDragReposition(true);
                        this.setTitle("Copy Cells");
                        this.setShowModalMask(true);
                        this.setIsModal(true);
                        this.addItem(form);

                        Record[] records = countryList.getSelectedRecords();
                        for (int i = 0; i < records.length; i++)
                        {
                                int index = countryList.getRecordIndex((ListGridRecord) records[i]);
                                if (index >= 0)
                                        records[i] = countryList.getEditedRecord(index);
                        }

                        DataSource dataSource = countryList.getDataSource();
                        String text = dataSource.recordsAsText(records, settings);
                        this.textArea.setValue(text);
                        this.textArea.selectValue();
                }
        };

        public void onClick(ClickEvent event)
        {
                this.new MyDialog().draw();
        }

        public void onClick(MenuItemClickEvent event)
        {
                this.new MyDialog().draw();
        }

        public void onCellContextClick(CellContextClickEvent event)
        {
                Menu menu = this.countryList.getContextMenu();
                menu.showContextMenu();
        }

        public void onModuleLoad()
        {
                DataSource dataSource = CountryXmlDS.getInstance();

                MenuItem item = new MenuItem("Copy");
                item.addClickHandler(this);

                Menu menu = new Menu();
                menu.setWidth(150);
                menu.addItem(item);

                ListGrid grid = new ListGrid();
                grid.setCanEdit(true);
                grid.setSize("100%", "100%");
                grid.setAutoFetchData(true);
                grid.setCanDragSelect(true);
                grid.setCanSelectCells(true);
                grid.setDataSource(dataSource);
                grid.setAutoFitData(Autofit.VERTICAL);
                grid.setContextMenu(menu);

                this.countryList = grid;

                Button button = new Button();
                button.setTitle("Copy Cells");
                button.addClickHandler(this);

                VLayout layout = new VLayout(15);
                layout.setSize("100%", "100%");
                layout.addMember(grid);
                layout.addMember(button);
                layout.draw();
        }

        public static class CountryXmlDS extends DataSource
        {

                private static CountryXmlDS instance = null;

                public static CountryXmlDS getInstance()
                {
                        if (instance == null)
                        {
                                instance = new CountryXmlDS("countryDS");
                        }
                        return instance;
                }

                public CountryXmlDS(String id)
                {

                        setID(id);
                        setRecordXPath("/List/country");
                        DataSourceIntegerField pkField = new DataSourceIntegerField("pk");
                        pkField.setHidden(true);
                        pkField.setPrimaryKey(true);

                        DataSourceTextField countryCodeField = new DataSourceTextField("countryCode", "Code");
                        countryCodeField.setRequired(true);

                        DataSourceTextField countryNameField = new DataSourceTextField("countryName", "Country");
                        countryNameField.setRequired(true);

                        DataSourceTextField capitalField = new DataSourceTextField("capital", "Capital");
                        DataSourceTextField governmentField = new DataSourceTextField("government", "Government", 500);

                        DataSourceBooleanField memberG8Field = new DataSourceBooleanField("member_g8", "G8");

                        DataSourceTextField continentField = new DataSourceTextField("continent", "Continent");
                        continentField.setValueMap("Europe", "Asia", "North America", "Australia/Oceania", "South America", "Africa");

                        DataSourceDateField independenceField = new DataSourceDateField("independence", "Nationhood");
                        DataSourceFloatField areaField = new DataSourceFloatField("area", "Area (km²)");
                        DataSourceIntegerField populationField = new DataSourceIntegerField("population", "Population");
                        DataSourceFloatField gdpField = new DataSourceFloatField("gdp", "GDP ($M)");
                        DataSourceLinkField articleField = new DataSourceLinkField("article", "Info");

                        setFields(pkField, countryCodeField, countryNameField, capitalField, governmentField,
                                        memberG8Field, continentField, independenceField, areaField, populationField,
                                        gdpField, articleField);

                        setDataURL("ds/country.data.xml");
                        setClientOnly(true);
                }
        }
}


Viewing all articles
Browse latest Browse all 4756

Trending Articles