PDA

View Full Version : Form and data store: examples?



ssamayoa
11 Jan 2011, 10:44 AM
Hi.

I just finished a java class and servlet which implemets JS's JsonStore actions (read, create, update, destroy) for JPA entities.

I want any data access (even forms) via store.

So far so good but I bump with a "problem": forms.

I look arround and found partial solutions/code but I dont understand how to implement using loadRecord() / beginEdit() / endEdit() / updateRecord() and so.

Someone has an example on how to do that?

Thanks.

11 Jan 2011, 1:24 PM
stores can read data from a Record. loadRecord is a form method, where beginEdit and endEdit are Record methods.



To see records being edited: http://extjsinaction.com/examples/chapter08/EditorGridPanel_with_manual_CRUD(local_web_server_only).html

ssamayoa
11 Jan 2011, 1:41 PM
@jgarcia:

Thanks but is not what I expected as response :(

I figure that with 2m ExtJS developers someone already did (or use in daily basis) the same task what I want to acomplish so he/she show me some codesnippet.

There is a lot of code and examples about posting data from form but none example of what I think is a better practice: route ALL data thru store.

Dont worry, I will do my homework and write the appropiate code.

Regards.

11 Jan 2011, 1:49 PM
@jgarcia:

Thanks but is not what I expected as response :(

I figure that with 2m ExtJS developers someone already did (or use in daily basis) the same task what I want to acomplish so he/she show me some codesnippet.

There is a lot of code and examples about posting data from form but none example of what I think is a better practice: route ALL data thru store.

Dont worry, I will do my homework and write the appropiate code.

Regards.

OK, so what you're looking to do is get the values from the form and set the appropriate keys on the record.



var key, vals = form.getForm().getValues();

record.beginEdit();
for (key in vals) {
record.set(key, vals[key]);
}
record.endEdit();
record.commit();

ssamayoa
11 Jan 2011, 2:33 PM
Oh!

Let me see:

1. Get the record to edit, ex:


var r = store.getAt(n); or


var r = store.getById(someId);2. Set form values:

someFormPanel.getForm().loadRecord(r);
3. Edit the record... (show dialog/window or whatever...)

4. Save the record:


r.beginEdit();
someFormPanel.getForm().updateRecord(r);
r.endEdit();
r.commit();
5. Save changes (if store.autoSave = false) in the server.


store.save();
For new record:

1. Create the record:



var r = new store.recordType();
2. Set form values:


someFormPanel.getForm().loadRecord(r);
QUESTION: Field.defaultValue is set when new record is constructed?
QUESTION: When record is constructed the appropiate data types are used? I mean, if I have a number field is initialized to 0, defaultValue or null?

3. Edit the record... (show dialog/window or whatever...)

4. Save the record to the store:


someFormPanel.getForm().updateRecord(r);
store.add([r]);
QUESTION: Since record isnt attached to store I guess no need to begin/end edit nor commit(), isnt?

5. Save changes (if store.autoSave = false) in the server.


store.save();
Thanks.