全て、
Extjs の JSONStore を使用して POST 経由で新しいレコードを作成しようとすると、キャスト例外が発生します。空の文字列がサーバーに渡され、サーバーがそれを整数に変換しようとすると、例外が発生します。コンボ ボックスの valueField は、int 定義のフィールドに設定されます。データストア フィールドは次のとおりです。
fields: [
{ name: 'id', type: 'int' },
{ name: 'displayOrder', mapping: 'displayOrder', type: 'int' },
{ name: 'displayName', mapping: 'displayName', type: 'string' },
{ name: 'enabled', mapping: 'enabled', type: 'boolean' },
{ name: 'letterCode', mapping: 'letterCode', type: 'string' }
],
コンボボックスの定義は次のとおりです。
{
xtype: 'combo',
id:"secondaryIncidentCombo",
hiddenName: 'secondaryIncidentTypeId',
forceSelection: true,
width:"200",
selectOnFocus: true,
emptyText: 'Secondary Incident',
editable: false,
mode: 'local',
displayField: 'displayName',
valueField: 'id',
store: this.secondaryIncidentTypeArrayStore,
triggerAction: 'all'
},
POST を送信するために使用される JSONStore は、奇妙なことに、変更されていないフィールドを送信しないように JSONWriter を構成したにもかかわらず、コンボボックスの値を空の文字列として送信します。
writer: new Ext.data.JsonWriter({
encode: false,
writeAllFields:false
}),
サーバーに送信される POST 値: ....,"secondaryIncidentTypeId":"",...
<-- コロンの後の空の文字列に注意してください。
次に、secondaryIncidentTypeArrayStore を示します。
secondaryIncidentTypeArrayStore: new Ext.data.ArrayStore({
idProperty: 'id',
fields: [
{ name: 'id', mapping: 'id', type: 'int' },
{ name: 'displayOrder', mapping: 'displayOrder', type: 'int' },
{ name: 'displayName', mapping: 'displayName', type: 'string' },
{ name: 'enabled', mapping: 'enabled', type: 'boolean' },
{ name: 'letterCode', mapping: 'letterCode', type: 'string' }
],
data: []
})
空の文字列の手動チェックを作成し、文字列が空の場合は null に設定しようとしています。これはかなり厄介なようです。フォーム送信時にサーバーに何も返さないか、または null 値を送信する正しい方法は何ですか?
ありがとう!