1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    84
    Vote Rating
    0
    koolll is on a distinguished road

      0  

    Default Unanswered: Refresh form panel and get the latest record after add or update any record

    Unanswered: Refresh form panel and get the latest record after add or update any record


    Hi, I am new for sencha touch. I need to add or update some record to my database. But now I got a question , how can I refresh my form panel and get the latest record after I add or update any record? By the way I am using jersey for the restful proxy

    Here is my code
    controller.js
    Code:
            var myStore= new Ext.data.Store({            model: 'bluebutton.model.BlueButton.MemberList'
            });
    
    
                var newModel = Ext.ModelMgr.create({ 'title': 1,
                            'singer': 2,
                        }, 'bluebutton.model.BlueButton.MemberList');
    
    
                myStore.add(newModel);
    
    
                myStore.sync();

    Store.js
    Code:
    Ext.define('bluebutton.model.BlueButton.MemberList', {
        extend: 'Ext.data.Model',
        config: {
            idProperty: 'memberModel',
            fields: [
                { name: 'title' },
                { name: 'singer' },
    
    
            ],
    
    
            proxy: {
                type: 'rest',
                url: 'http://localhost:8080/RESTFulExample/rest/json/metallica/post3',
                useDefaultXhrHeader: false,
                noCache: false,
                reader: 'json',
                actionMethods: {
                    create: 'POST',
                    read: 'POST',
                    update: 'POST',
                    destroy: 'POST'
                }
            }
    
    
            //                    proxy: {
            //                    type: 'rest',
            //                    url: 'http://192.168.0.103:8080/RESTFulExample/rest/json/metallica/post'
            //            }
    
    
    
    
    
    
    
    
    
    
        }
    
    
    });

    Jersey.java
    Code:
    		@POST
    		@Path("/post3")
    		@Produces(MediaType.APPLICATION_JSON)
    		public Track getTrackInPost3(String title) {
    	 
    			//--Assume return this record after adding any record-
    			Track track = new Track();
    			track.setTitle("Enter Sandman");
    			track.setSinger("Metallica");
    	 
    			return track;
    	 
    		}

    Please guide me so solution . Thanks

  2. #2
    Sencha User
    Join Date
    Nov 2012
    Location
    Netherlands
    Posts
    50
    Answers
    6
    Vote Rating
    1
    eastlander is on a distinguished road

      0  

    Default


    The sync method returns the updated record. So you could do:

    Code:
    var newRecord = myStore.sync();
    myFormpanel.setRecord(newRecord);

  3. #3
    Sencha User
    Join Date
    Nov 2012
    Posts
    84
    Vote Rating
    0
    koolll is on a distinguished road

      0  

    Default


    Hi, thanks for your reply.I now got a question. How can I update my record?

    Here is my code
    controller.js
    Code:
            var User = Ext.ModelMgr.getModel('bluebutton.model.BlueButton.MemberList');        User.save({
                success: function(user) {
                    user.set('name', 'Khan Noonien Singh');
    
    
                    user.save(); //PUT /users/123
                }
            });
    Model.js
    Code:
    Ext.define('bluebutton.model.BlueButton.MemberList', {
        extend: 'Ext.data.Model',
        config: {
            idProperty: 'memberModel',
            fields: [
                { name: 'title' },
                { name: 'singer' },
    
    
            ],
    
    
            proxy: {
                type: 'rest',
                url: 'http://localhost:8080/RESTFulExample/rest/json/metallica/get',
                reader: 'json',
                actionMethods: {
                    create: 'POST',
                    read: 'GET',
                    update: 'PUT',
                    destroy: 'POST'
                },
    
    
                reader: {
                    type: 'json',
                    root: 'Track'
                },
    
    
                writer: {
                    type: 'json',
                  
                },
            }
    
    
            //                    proxy: {
            //                    type: 'rest',
            //                    url: 'http://192.168.0.103:8080/RESTFulExample/rest/json/metallica/post'
            //            }
    
    
    
    
    
    
    
    
    
    
        }
    
    
    });
    Jersey.java
    Code:
    	//--Update record	@PUT
    	@Path("/get/{userID}")
    	@Produces(MediaType.APPLICATION_JSON)
    	public Track getTracktest1(@PathParam(value = "userID") String accountId) {
     
    		Track track = new Track();
    		track.setTitle("Enter Sandman");
    		track.setSinger("Metallica");
     
    		return track;
     
    	}
    My jersey cant get any put data. Please give me some example .Thanks


    Quote Originally Posted by eastlander View Post
    The sync method returns the updated record. So you could do:

    Code:
    var newRecord = myStore.sync();
    myFormpanel.setRecord(newRecord);

Thread Participants: 1

Tags for this Thread