Announcement

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

    Default summary function for SimpleType?

    I'm using a SimpleType that inherits from Float and adds a custom formatter. It works fine, but when a field of this type is shown in a ListGrid which has group or grid summaries, nothing shows up in the summary line. Shouldn't the SimpleType inherit the default summary function from Float? Is there another way to specify what the default summary function should be? I couldn't find any attribute for that in the SimpleType class.

    #2
    It gets worse. If I explicitly set a summary function on a ListGridField that uses my SimpleType field from the datasource, as in ...
    field.setSummaryFunction(SummaryFunctionType.SUM);

    I get the following runtime exception ...
    Code:
    java.lang.ClassCastException: null
        at java.lang.Class.cast(Class.java:2990)
        at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:163)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:65)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
        at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
        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:188)
        at sun.reflect.GeneratedMethodAccessor103.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.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
        at java.lang.Thread.run(Thread.java:637)

    Comment


      #3
      We'll take a look.

      Comment


        #4
        Hi Jay,
        I'm getting works-for-me with the following code (modified from the SimpleTypes example in the SGWT showcase).
        Could you see if you get the same issue with this code (if so it may be build issue). If not, any chance you could put together a simple standalone test case we could run to try it on our end, possibly starting with this code and making modifications to bring it closer to what you have in your application?

        Thanks

        Code:
            public void onModuleLoad() {  
          
                DataSource dataSource = new DataSource();  
          
                DataSourceField zipCodeField = new DataSourceField();  
                zipCodeField.setName("zipCode");  
                zipCodeField.setTitle("Zip Code");  
                zipCodeField.setType(new ZipCodeUSType());  
          
                dataSource.setFields(zipCodeField);  
                  
                dataSource.setClientOnly(true);
                
                ListGridRecord record  = new ListGridRecord();
                record.setAttribute("zipCode", 122);
                ListGridRecord record2 = new ListGridRecord();
                record2.setAttribute("zipCode", 133);
                
                dataSource.setTestData(new Record[] {
                		record, record2        		
                });
                
          
                VLayout layout = new VLayout(10);  
                layout.setWidth(400);
                layout.setHeight100();
                
                ListGrid testGrid = new ListGrid();
                testGrid.setDataSource(dataSource);
                testGrid.setAutoFetchData(true);
                
                ListGridField zipField = new ListGridField("zipCode");
                zipField.setSummaryFunction(SummaryFunctionType.SUM);
                
                testGrid.setFields(new ListGridField[] {zipField});
              
                testGrid.setShowGridSummary(true);
                
                layout.addMember(testGrid);
          
                layout.draw();  
            }  
          
            public static class ZipCodeUSType extends SimpleType {  
                public ZipCodeUSType() {  
                    super("zipCodeUS", FieldType.FLOAT);  
        //            setInheritsFrom(FieldType.FLOAT);
          
                    RegExpValidator validator = new RegExpValidator("^\\d{5}(-\\d{4})?$");  
                    setValidators(validator);  
                }  
            }

        Comment


          #5
          Finally getting back to this. The difference is that I'm setting the type in the ds.xml as in <field name="RetailPrice" type="currency"/>. Then in my module entry point I have the following code.
          Code:
          // Create a SimpleType for currency fields and set the formatters.
          currencyType = new SimpleType("currency", FieldType.FLOAT);
          currencyType.setNormalDisplayFormatter(new SimpleTypeFormatter() {
          
          	@Override
          	public String format(Object value, DataClass field,
          			DataBoundComponent component, Record record) {
          		if (value==null) return null;
          		Double valueDouble = Double.valueOf(value.toString());
          		if (valueDouble==null) return "";
          		else return homeCurrencyFormat(valueDouble);
          	}
          });
          currencyType.setShortDisplayFormatter(new SimpleTypeFormatter() {
          
          	@Override
          	public String format(Object value, DataClass field,
          			DataBoundComponent component, Record record) {
          		if (value==null) return null;
          		Double valueDouble = Double.valueOf(value.toString());
          		if (valueDouble==null) return "";
          		else return homeCurrencyFormat(valueDouble);
          	}
          });
          currencyType.register();
          So I'm not creating a subclass of SimpleType and calling super and using that class to DSField.setType(). I'm hoping to avoid having to code something special for each field of type "currency" and instead just define the type and use it in the ds.xml. Is that not possible? The formatters work as expected, it's just that the default summary function is not "inherited" from the base type of Float and I get an error if I try to set a summary function.

          Comment


            #6
            Any update? Is is possible to do what I'm trying to do? The example you sent is creating the datasource in code on the client. I need to use the ds.xml approach.

            Comment


              #7
              Hi Jay.
              This should be possible but agreed it's not currently working. We're looking at it and we'll let you know when we have something.

              Comment


                #8
                Please try the latest build.

                Comment


                  #9
                  Just tried the 2.3 Pro release and it does seem to be working fine. Thanks!

                  Comment

                  Working...
                  X