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.
Announcement
Collapse
No announcement yet.
X
-
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)
-
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
-
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();
Comment
Comment