7

Folks,

I have a combobox component backed by a JSONStore. The data loaded into the store is returning null for the combobox's value. The value is an int. The JSON decode process is converting the null value into a zero; causing the combobox to fail to render when it attempts to find the pk, zero that doesn't exist in its backing store.

I've found the useNull: config option for data.Field objects, upgraded to 3.3.0 Final and set my int value for the combobox to useNull:true. This isn't having any affect at all, unfortunately. The decoded value is still being changed from null to zero.

Any ideas about how to not set the field to a zero when the data for a JSON field is null?

Here's a pic of what's going on. Notice the data: value is zero, but the JSON value is null.

Thanks!

(gah! stoopid reputation < 10 so I can't directly post the pic. View it here: debug pic )

Also, here's my store's field config:

  fields: [
        {name:"id", type:"int"},
        {name:"occurenceDate", dateFormat: 'Y-m-d\\TH:i:s', type:"date"},
        {name:"docketNumber", type:"string"},
        {name:"courtLocationId", type:"int", useNull:true},
        {name:"assignedOfficerId", type:"int", useNull:true},
        {name:"primaryIncidentTypeId", type:"int", useNull:true},
        {name:"secondaryIncidentTypeId", type:"int", useNull:true},
        {name:"tertiaryIncidentTypeId", type:"int", useNull:true},
        {name:"incidentLocation", type:"string"},
        {name:"summary", type:"string"},
        {name:"personalItemsSeized", type:"string"},
        "supplements",
        "parties",
        "judgeIds"
    ]
John Gordon
  • 2,181
  • 5
  • 28
  • 47
  • Now I'm not sure the combobox's rendering issues are because of un-mappable values coming from the server. I configured the JSONObjectMapper to not return null fields to the client like so (using Jackson w/ Spring): setSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); now the null fields are not returning, but the combobox is still failing to render correctly. Still researching.... – John Gordon Nov 01 '10 at 18:28

4 Answers4

3

Try using it without type declaration. You may also use convert method:

{
    name: "primaryIncidentTypeId", 
    convert: function(value, row) {
        return (value == null) ? null : parseInt(value);
    }
}
Donatas Olsevičius
  • 1,350
  • 8
  • 13
  • Thanks for the tip. I successfully added the above (only difference: Ext.isEmpty(value) -- the value is an empty string and != null). That solved the issue of JSON translating a null value to a zero, but it didn't resolve the problem where my combo boxes were shrinking. I discovered that you have to explicitly set the width: config for a combobox, otherwise the combos will shrink. – John Gordon Nov 02 '10 at 19:44
  • Another note: I ran into two issues during this process. The 1st is that the convert: function I defined in the fields: param of the store were never being called. The reason is because I was returning column meta data from the server in the get that populated the store; overwriting what I had hard coded in the client-side javascript config. – John Gordon Nov 02 '10 at 19:49
  • The second issue was with Extjs 3.3.0. the final release has what I think is a bug when asking a BasicForm to updateRecord() on a form whose fields are null. The issue is in the bowels of BasicForm's updateRecord(): it iterates through its fields calling getValue(), but then calls value.groups -- or something like that. If the value is null, it's not an object and...KABOOM. Any ideas on this one? I'd love to upgrade to 3.3 so I can use the useNull: property instead of converters. – John Gordon Nov 02 '10 at 19:53
0

About the combo width: I usually use

defaults: {
    anchor: '100%'
}

in the form declaration and have no problems with widths.

Isnt't it possible to provide convert functions from server side together with all other metadata?

And I'm still using ExtJS 3.2 - no need of any new bugs in the production systems :)

Donatas Olsevičius
  • 1,350
  • 8
  • 13
  • Yes, you can provide the convert functions in the meta data from the server side, sorry for not pointing that out. We use some server-side code to generate extjs store metadata based on any java bean. Our process isn't sophisticated enough yet to include converters in the generated code. – John Gordon Nov 04 '10 at 13:09
  • thanks for the tip re `anchor: '100%'` I've used it, but my form is too wide for it to be attractive. I'll have to figure something out like putting in columns into the form to manage the size. until I de-lazy-i-fy myself, i'll stick with width: . :-) – John Gordon Nov 04 '10 at 13:10
0

This also got me, you can additionally override the type convert function in Ext.data.Types to allow null values for integer type fields.

Ext.data.Types.INT.convert = function(v){
  v = parseInt(String(v).replace(Ext.data.Types.stripRe, ''), 10);
  return isNaN(v) ? null : v;
};
Alex
  • 409
  • 3
  • 6
-1

You must use defaultValue: null ,useNull : true because default value for integet type is zero

Example:

{name:"primaryIncidentTypeId", type:"int", useNull:true , defaultValue: null },
Matthew Verstraete
  • 6,335
  • 22
  • 67
  • 123
mojtaba roohi
  • 711
  • 5
  • 4