服务器端未收到Extjs 5.0模型POST值(正在运行Extjs 4.2) [英] Extjs 5.0 model POST values not received on server side (working Extjs 4.2)

查看:65
本文介绍了服务器端未收到Extjs 5.0模型POST值(正在运行Extjs 4.2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我们的Extjs 4.2应用程序升级到Extjs 5.0.
我能够调出所有只读页面,但是当我尝试更新/保存数据时遇到问题.非常感谢您的帮助!

I am upgrading our Extjs 4.2 app to Extjs 5.0.
I am able to bring up all the read only pages but i am getting issues when i try to update/save the data. I will really appreciate your help!!

我的模型数据值未在服务器端显示,我能够使用console.log(model)打印模型,并且它具有所有值, ,但是在服务器端,它仅具有id和所有其他参数显示为空.

My model data values are not showing up on the server side, i am able to print model with console.log(model) and it has all the values , but on the server side it only has id and all the other parameters are showing as null.

以下是该模型中的代理:

Here is proxy in the model :


     Ext.define('MyApp.model.User', {
      extend: 'Ext.data.Model',
      id: 'user',
      proxy: {
        type: 'rest',
        url : '/rest/update/user',
        listeners: {
          exception: function(proxy, response, operation) {
            Ext.Msg.alert('Failed', 'Save the user Failed!');
          }
        }
      },
      fields: [
        {name: 'id', type: 'int'},
        {name: 'userName', type: 'string'},
        {name: 'country', type: 'string'}
        ]
    }

控制器:

onUserUpdateAction: function(button, event, action) { 

      var model = Ext.create('MyApp.model.User');    
      model.set('id', "123"); 
      model.set('userName', "john");
      model.set('country', "usa");
      ---
      model.commit() / without commit() it does not add the id in URL like /user/123
      model.save();
}

这是服务器端代码:

@PUT
@Consumes({ "application/json" })
@Path("/Update/user/{id}")
updateUser(@PathParam("id") final int id, final User record);

实现类中的第一行日志,id在那里,但其他所有值都为空

First line log in the implementation class, id is there but all the other values are null

*** In updateUser() method, id : 123, record: User(id=123, **userName=null, country=null**)

推荐答案

这里的问题是您试图欺骗Ext.您创建带有ID的新记录-通常ID是由服务器分配的.因此,您需要提交它以清除phantom(新记录)标志,以便Ext认为它已经存在.但是,提交后,记录没有修改的字段,并且默认情况下,仅将修改的字段发送到服务器.因此,您需要配置一个编写器,如下所示:

The problem here is that you try to fool the Ext. You create new record with id - normally ids are assigned by the server. Therefore, you need to commit it to clear it phantom (new record) flag, so that Ext thinks it is already existing record. But, after commit, the record has no modified fields and, by default, only modified fields are sent to the server. Therefore, you need a writer configured, something like this:

Ext.define('MyApp.model.User', {
    extend: 'Ext.data.Model',
    idProperty: 'id',
    fields: [
        {name: 'id', type: 'int'},
        {name: 'userName', type: 'string'},
        {name: 'country', type: 'string'}
    ],

    proxy: {
        type: 'rest',
        url : 'success.php',
        listeners: {
            exception: function(proxy, response, operation) {
                Ext.Msg.alert('Failed', 'Save the user Failed!');
            }
        }
        ,writer:{
             type:'json'
            ,writeAllFields:true
        }
    }
});

这篇关于服务器端未收到Extjs 5.0模型POST值(正在运行Extjs 4.2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆