Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DataSource.recordsAsText() causes TypeError exception

    1. SmartGWT 3.1p_2012_11_30/Evaluation
    2. FireFox 17.0.1

    I try to integrate grid-to-excel functionality to my application.
    I just copied sample code from the SmaprtGWT Showcase and set some minimal changes:
    Code:
    	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 = 800;  
    	        final int HEIGHT = 600;  
    	
    	        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 = RDXSimpleGrid.this.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(RDXSimpleGrid.this.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");  
    	        this.setShowModalMask(true);  
    	        this.setIsModal(true);  
    	        this.addItem(form);  
    	
    	        DataSource dataSource = RDXSimpleGrid.this.getDataSource();  
    	        Record[] records = RDXSimpleGrid.this.getSelectedRecords();
    	        
    	        String text = dataSource.recordsAsText(records, settings);  
    	
    	        this.textArea.setValue(text);  
    	        this.textArea.selectValue();  
    	    }  
    };
    It can get selected cells, but dataSource.recordsAsText(records, settings) causes Exception:

    Code:
    com.google.gwt.event.shared.UmbrellaException: Exception caught: (TypeError) @com.smartgwt.client.data.DataSource::recordsAsText([Lcom/smartgwt/client/data/Record;Lcom/smartgwt/client/data/TextExportSettings;)([Java object: [Lcom.smartgwt.client.data.Record;@525578931, Java object: com.smartgwt.client.data.TextExportSettings@2068127750]): _4.replace is not a function
    	at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
    	at com.smartgwt.client.core.DataClass.fireEvent(DataClass.java:248)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	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.GeneratedMethodAccessor30.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	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(Unknown Source)
    Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError) @com.smartgwt.client.data.DataSource::recordsAsText([Lcom/smartgwt/client/data/Record;Lcom/smartgwt/client/data/TextExportSettings;)([Java object: [Lcom.smartgwt.client.data.Record;@525578931, Java object: com.smartgwt.client.data.TextExportSettings@2068127750]): _4.replace is not a function
    	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 org.ridex.gwt.module.client.component.RDXSimpleGrid$MyDialog.<init>(RDXSimpleGrid.java:679)
    	at org.ridex.gwt.module.client.component.RDXSimpleGrid$8.onClick(RDXSimpleGrid.java:404)
    	at com.smartgwt.client.widgets.menu.events.MenuItemClickEvent.dispatch(MenuItemClickEvent.java:100)
    	at com.smartgwt.client.widgets.menu.events.MenuItemClickEvent.dispatch(MenuItemClickEvent.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)
    	... 26 more
    com.google.gwt.core.client.JavaScriptException: (TypeError) @com.smartgwt.client.data.DataSource::recordsAsText([Lcom/smartgwt/client/data/Record;Lcom/smartgwt/client/data/TextExportSettings;)([Java object: [Lcom.smartgwt.client.data.Record;@525578931, Java object: com.smartgwt.client.data.TextExportSettings@2068127750]): _4.replace is not a function
    	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 org.ridex.gwt.module.client.component.RDXSimpleGrid$MyDialog.<init>(RDXSimpleGrid.java:679)
    	at org.ridex.gwt.module.client.component.RDXSimpleGrid$8.onClick(RDXSimpleGrid.java:404)
    	at com.smartgwt.client.widgets.menu.events.MenuItemClickEvent.dispatch(MenuItemClickEvent.java:100)
    	at com.smartgwt.client.widgets.menu.events.MenuItemClickEvent.dispatch(MenuItemClickEvent.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.core.DataClass.fireEvent(DataClass.java:248)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	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.GeneratedMethodAccessor30.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	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(Unknown Source)
    It looks like internal JS error: "_4.replace is not a function".

    Grid created as grid.setDataSource(DataSource.get("WMS_ACCOUNT")) and then this method invoked once inside the grid to set CellFormatter:

    Code:
    	public void setCellFormatter(String cellName, CellFormatter cellFormatter)
    	{
    		ListGridField[] fields = getFields();
    		
    		if (fields == null || fields.length == 0)
    			return;
    		
    		for (int i = 0; i < fields.length; i++)
    		{
    			if (fields[i].getName().equals(cellName))
    			{
    				fields[i].setCellFormatter(cellFormatter);
    				setFields(fields);
    				break;
    			}
    		}
    	}
    DataSource:
    Code:
    <DataSource 
    dropExtraFields="true"
    	willHandleAdvancedCriteria="true" 
    ID="WMS_ACCOUNT"  
        serverConstructor="org.ridex.gwt.core.server.data.RDXJPA2DataSource"
        pathForBMPHandlers="org.ridex.wms.core.server.bpm.applications" 
        beanClassName="org.ridex.wms.core.dom.Account"
    >
    	<fields>
    		<field name="id" title="#"   width="36" canEdit="false" type="sequence"   hidden="false"   primaryKey="true" />
    		<field name="number" title="0" type="text" required="true" canEdit="true"></field>
            <field name="date" title="1" type="date" required="true" canEdit="true"></field>
    		
    	       
            <field name="payerTitle" title="2" type="text" hidden="false" form.hidden="true" valueXPath="payer/title" canEdit="false" canSave="false"/>
            <field name="payer" title="2"
            		form.hidden="false"
            		form.optionDataSource="WMS_CONTRACTOR"
            		form.displayField="title"
            		form.valueField="id"        		     		
            		hidden="true" canEdit="true" required="true" foreignKey="WMS_CONTRACTOR.id" />
      
    
    		<field name="contractorTitle" title="4" type="text" hidden="false" form.hidden="true" valueXPath="contractor/title" canEdit="false" canSave="false"/>
    		<field name="contractor" title="4"
    				form.hidden="false"
            		form.optionDataSource="WMS_CONTRACTOR"
            		form.displayField="title"
            		form.valueField="id"   
    		 		hidden="true" canEdit="true" required="true"   foreignKey="WMS_CONTRACTOR.id" />
    		
    		<field name="sum" title="5" type="float"></field>
    
    		<field name="contractNumber" title="6" type="text" hidden="false" form.hidden="true" valueXPath="contract/number" canEdit="false" canSave="false"/>
    		<field name="contract"  title="6"
    				form.hidden="false"
            		form.optionDataSource="WMS_CONTRACT"
            		form.displayField="number"
            		form.valueField="id"
    				hidden="true" canEdit="true" required="false" foreignKey="WMS_CONTRACT.id" />
    		
    		<field name="targetOfPayment" title="7" hidden="false" canEdit="true" required="false" optionDataSource="WMS_TARGET_OF_PAYMENT" valueField="id" displayField="title"  foreignKey="WMS_TARGET_OF_PAYMENT.id" />
    		
    		<field name="accountStatus"  title="8" hidden="false" canEdit="true" required="true" optionDataSource="WMS_ACCOUNT_STATUS" valueField="id" displayField="title"  foreignKey="WMS_ACCOUNT_STATUS.id" />
    		
    		<field name="creationDate" title="9" width="16" hidden="false" form.hidden="true" canEdit="false" canSave="false" type="datetime"  valueXPath="document/creationDate" /> 
    		<field name="author" title="10" width="16" hidden="false" form.hidden="true" canEdit="false" canSave="false" type="text"  valueXPath="document/author/name" /> 
    		
    		<field name="deleted" title="11" form.hidden="true" width="36" type="boolean" valueXPath="document/deleted" canEdit="true" />
            <field name="archived" title="12" form.hidden="true" width="36" type="boolean" valueXPath="document/archived" canEdit="true" />
            <field name="documentId" title=" " width="16" hidden="false" canEdit="false" canSave="false" type="long"  valueXPath="document/id" /> 
            
            <field name="document" title="13"  hidden="true" form.hidden="true" canEdit="false" canSave="false" foreignKey="WMS_DOCUMENT.id" /> 
    	</fields>
    </DataSource>
    What can I do with that?
    Please, help.

    #2
    We've made a fix to the SC 8.3p/SGWT 3.1p code streams that should address the crash you're seeing. It should be in the next nightly build.

    If there is still an issue, please let us know.

    Comment


      #3
      I updated with SmartGWT 3.1p that I downloaded today.

      There is the same error in the same place.

      Comment


        #4
        Please take a look at the instructions in the FAQ to conclusively verify you're actually loading the new code (and not being fooled by caching, etc). Please report what you find. If you're clearly loading the new version, we can take another look.

        Comment


          #5
          After Eclipse restarting it works well.

          I've just noticed that for the field "targetOfPayment" (look at DS code above) I have values instead of displayValues in the dialog. For the other fields mapped with valueXPath I have right values as in the grid.

          Is it feature or a bug?

          And formatter value of the "sum" field does not look like in the grid. It's not formatted in the values list in the dialog.

          Comment


            #6
            Actually the copy mechanism uses an array of Records to get a column data. It doesn't contain data from optionDS and mapping.
            So, how to get displayValues ? I want to copy them but not values.

            Comment


              #7
              We've added a new boolean property, TextExportSettings.useDisplayValue, to force the display value of a DataSourceField to be used rather than the raw value. This should be present in SC 9.0d/SGWT 4.0d and SC 8.3p/SGWT 3.1p in the next nightly build.

              Comment


                #8
                I know this is an old thread but I am trying to do the same thing. I've created my TextExportSettings object with useDisplayValue: true but I'm still getting the underlying values. Has this been tested recently? Is there a showcase example? Thanks.

                Comment


                  #9
                  Yes there's an example at http://www.smartclient.com/smartgwt/...excel_category, and the feature appears to be working.

                  Comment


                    #10
                    Thanks but that example does not use the useDisplayValue property, which is what I'm asking about. I am using SmartClient (not SmartGWT) although I trust that if it works in one, it will work in the other. I just haven't seen it work at all and wonder if I may be doing something wrong.

                    Comment

                    Working...
                    X