Announcement

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

    Getting computed value of ListGrid formula builder

    I'm trying to get the computed value (by code) of a Field that was created using the Formula Builder. I've tried ListGrid.getFormulaFieldValue() as well as getSummaryFieldValue(), both methods seems to always throw a null pointer exception. Is this the intended way to get the computed value?

    I'm using SmartGWT EE v2.5 (Eval)
    sample code and stacktrace below.


    Thanks!

    -DavidK

    Code:
     
    		VLayout layout = new VLayout(15);
    
    		final ListGrid countryGrid = new ListGrid();
    		countryGrid.setLeaveScrollbarGap(true);
    
    		countryGrid.setWidth(750);
    		countryGrid.setHeight(224);
    		countryGrid.setDataSource(DataSource.get(AnalysisDataSourceNames.device.toString()));
    		countryGrid.setAutoFetchData(true);
    
    		// allow users to add formula and summary fields
    		// accessible in the grid header context menu
    		countryGrid.setCanAddFormulaFields(true);
    		countryGrid.setCanAddSummaryFields(true);
    		countryGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {
    
    			@Override
    			public void onRecordDoubleClick(RecordDoubleClickEvent event) {
    				SC.say("" + countryGrid.getFormulaFieldValue(event.getField(), event.getRecord()));
    
    			}
    		});
    
    		layout.addMember(countryGrid);
    
    		HLayout buttonLayout = new HLayout(15);
    
    		IButton formulaButton = new IButton("Show Formula Builder");
    		formulaButton.setAutoFit(true);
    		formulaButton.addClickHandler(new ClickHandler() {
    			public void onClick(ClickEvent event) {
    				countryGrid.addFormulaField();
    			}
    		});
    
    		IButton summaryBuilder = new IButton("Show Summary Builder");
    		summaryBuilder.setAutoFit(true);
    		summaryBuilder.addClickHandler(new ClickHandler() {
    			public void onClick(ClickEvent event) {
    				countryGrid.addSummaryField();
    			}
    		});
    
    		buttonLayout.addMember(formulaButton);
    		buttonLayout.addMember(summaryBuilder);
    
    		layout.addMember(buttonLayout);
    
    		return layout;
    Code:
    11:23:15.893 [ERROR] [rtimms] Uncaught exception escaped
    
    com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
        at com.google.gwt.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:214)
        at com.google.gwt.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:103)
        at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:101)
        at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:67)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        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:157)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:129)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
        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:214)
        at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        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:157)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
        at java.lang.Thread.run(Thread.java:662)
    Caused by: com.google.gwt.core.client.JavaScriptException: (null): null
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:129)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeInt(ModuleSpace.java:245)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeInt(JavaScriptHost.java:75)
        at com.smartgwt.client.widgets.grid.ListGrid.getFormulaFieldValue(ListGrid.java)
        at com.intelights.rtimms.client.ui.widgets.smartgwt.DevModeEntryPoint$2.onRecordDoubleClick(DevModeEntryPoint.java:83)
        at com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent.dispatch(RecordDoubleClickEvent.java:98)
        at com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent.dispatch(RecordDoubleClickEvent.java:1)
        at com.google.gwt.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:204)
        at com.google.gwt.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:103)
        at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:101)
        at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:67)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        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:157)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:129)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
        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:214)
        at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        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:157)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
        at java.lang.Thread.run(Thread.java:662)

    #2
    For any JavaScript error, please capture a stack trace from the SmartGWT Developer Console in compiled mode (see FAQ).

    Comment


      #3
      It appears no stack trace is logged in the SmartGWT Developer Console; its only logged in the Eclipse Console. I've tried putting console logging in to DEBUG level but it didnt seem to produce anything related to the error. I'm not sure if i'm missing something.

      Would this be a standard feature after we purchased the SmartGWT Power version? (The ability to get calculated formula builder record values by code).

      Thanks!

      Comment


        #4
        No, it does not require Power.

        You should look for the stack trace *in compiled mode*.

        Comment


          #5
          Sorry I wasnt aware compiled mode would behave differently to hosted mode.

          when ran in compiled mode, i'm actually not getting an exception, however the method "getFormulaFieldValue()" seem to always return a "." character when I try to convert the integer result to String (by adding it to empty string).

          In addition, I also see a WARN logged when getFormulaFieldValue() is invoked:

          Code:
          12:05:19.903:MUP5:WARN:Log:findByKeys: passed record does not have a value for key field 'id'
          I am also puzzled to why getFormulaFieldValue() and getSummaryFieldValue() both return integers. I'd expect the former to return a float or double and the latter to return a String. Am I misunderstanding something?

          Thanks!

          Comment


            #6
            Can you put together a minimal runnable test case where we can see this value being returned?

            Comment


              #7
              Here's the test code, i've pre-entered a formula that does not product the expected results. simply click the "Get formula values as CSV" and the a pop up appears with only periods and commas (eg: ".,.,.,.,.,.,.,.,")

              when i changed the formula for column 1 to "random()*100" then click the button, I get an expected list of comma-separated values.

              I'm using :
              GWT v2.2.0
              SmartGWT 2.5.0 (SC_SNAPSHOT-2011-08-08/EVAL Deployment)
              JDK 1.6.0_25
              Windows 7 - 64 bit

              browsers tested:
              IE9, Chrome v15, Firefox 5

              Code:
              package com.intelights.rtimms.client.ui.widgets.smartgwt;
              
              import com.google.gwt.core.client.EntryPoint;
              import com.smartgwt.client.data.DataSource;
              import com.smartgwt.client.data.Record;
              import com.smartgwt.client.data.RecordList;
              import com.smartgwt.client.data.fields.DataSourceFloatField;
              import com.smartgwt.client.data.fields.DataSourceIntegerField;
              import com.smartgwt.client.util.SC;
              import com.smartgwt.client.widgets.IButton;
              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.HLayout;
              import com.smartgwt.client.widgets.layout.VLayout;
              
              public class ListGridFormulaTest2 implements EntryPoint {
              
              	@Override
              	public void onModuleLoad() {
              		VLayout layout = new VLayout(15);
              		final ListGrid grid = new ListGrid();
              		grid.setLeaveScrollbarGap(true);
              		grid.setWidth(750);
              		grid.setHeight(224);
              
              		// set up test data
              		ListGridRecord[] data = new ListGridRecord[10];
              		for (int i = 0; i < data.length; i++) {
              			ListGridRecord rec = new ListGridRecord();
              			data[i] = rec;
              
              			rec.setAttribute("id", i);
              			rec.setAttribute("value", Math.random());
              		}
              
              		DataSourceIntegerField f1 = new DataSourceIntegerField("id");
              		f1.setPrimaryKey(true);
              		DataSourceFloatField f2 = new DataSourceFloatField("value");
              		DataSource ds = new DataSource();
              		ds.setFields(f1, f2);
              		ds.setTestData(data);
              		ds.setClientOnly(true);
              
              		// set up listgrid
              		grid.setDataSource(ds);
              		grid.setAutoFetchData(true);
              		grid.setCanReorderFields(false);
              		grid.setFieldState("[{name:\"formulaField1\",userFormula:{text:\"B*100\",formulaVars:{B:\"value\"}},title:\"Formula 1\",width:null},{name:\"id\",width:null},{name:\"value\",width:null}]");
              		grid.setCanAddFormulaFields(true);
              		grid.setCanAddSummaryFields(true);
              		layout.addMember(grid);
              
              		HLayout buttonLayout = new HLayout(15);
              
              		// button to get formula values
              		IButton getValsBtn = new IButton("Get formula values as CSV");
              		getValsBtn.setAutoFit(true);
              		getValsBtn.addClickHandler(new ClickHandler() {
              			public void onClick(ClickEvent event) {
              				SC.warn(grid.getFieldState());
              				ListGridField f = grid.getField(0);
              				RecordList recList = grid.getDataAsRecordList();
              				String vals = "";
              				for (int i = 0; i < recList.getLength(); i++) {
              					Record rec = recList.get(i);
              					vals += grid.getFormulaFieldValue(f, rec) + ", ";
              				}
              				SC.say(vals);
              				SC.warn(vals);
              			}
              		});
              
              		buttonLayout.addMember(getValsBtn);
              
              		layout.addMember(buttonLayout);
              
              		layout.draw();
              	}
              }

              Comment


                #8
                hi, did you get a chance to confirm if this is a bug? if it is, i dont expect a fix immediately as i'm sure you have higher priorities. As this is a critical feature in our system, I'd like to confirm if this feature will satisfy our requirements. Also I'd like to know how soon can this be fixed when we purchased the SmartGWT Power edition?

                We already submitted a P.O. internally for approval to purchase the SmartGWT Power edition; its lumped with a bunch of other equipment P.O. so it may take up to a month before approval.

                thanks!

                David.

                Comment


                  #9
                  From code inspection your test case looks OK, it's queued to have someone take a look at the cause, but it's behind other reports because you don't have support - getting support is the right way to get it looked at quickly (see the available plans).

                  Sounds like you have a long procurement process - if it's not already on there, you should probably see about getting support plans as part of the purchase, so that we'll be able to jump on any bug reports right away.

                  Comment


                    #10
                    Originally posted by Isomorphic
                    From code inspection your test case looks OK, it's queued to have someone take a look at the cause, but it's behind other reports because you don't have support - getting support is the right way to get it looked at quickly (see the available plans).

                    Sounds like you have a long procurement process - if it's not already on there, you should probably see about getting support plans as part of the purchase, so that we'll be able to jump on any bug reports right away.
                    Hey Isomorphic,

                    any update on the the status of the problem ? I'm currently having the same problem when calling getFormulaFieldValue.

                    +

                    The width (or autoWidth:true) of the FormulaField seems to be missing when the field gets added to the grid:

                    http://www.smartclient.com/smartgwt/...umamry_builder

                    Add a simple formula field like A+10 and keep the title and look at the width of the field.

                    Fieldstate of my formula field:

                    {name:"formulaField1",
                    userFormula:{text:"A+2",
                    formulaVars:{A:"age"}},
                    title:"New Field",
                    width:null},

                    Fieldstate example of my other (=regular) fields:

                    {name:"ecelectricity",
                    width:120,
                    autoFitWidth:true},

                    Can I specify the width (minWidth or autoFitWidth) behavior on a formulaField before it gets added ?

                    Thanks & Best regards,

                    shift
                    Last edited by shift; 22 Oct 2011, 04:13.

                    Comment


                      #11
                      Hi there,

                      any fixes landed in 2.5 yet ? This is obviously a BUG in 2.5 ?!

                      Cheers,

                      shift

                      Comment

                      Working...
                      X