PDA

View Full Version : Stores and Rolling Back Changes



brendand
19 May 2009, 6:01 AM
I'm trying to figure out a way to use wizards that update Stores, but roll back the changes if the wizard is not competed. I only want other parts of the App to be notified of the change when the wizard completes (and I commit the changes).

Ideally I want to have several forms that are bound to the Store, one of the forms will be in the wizard, and another form will not be in the wizard. The second form should get notified when I commit the store changes.

Here is some code I have been experimenting with. I was trying to get record.cancelEdit() and store.rejectChanges() to work, but they don't roll back. Perhaps I'm missing something obvious, or don't understand how they work.

You can see it not working here. http://brendan-test.appspot.com/



package com.example.commitTest.client;

import java.io.Serializable;

public class User implements Serializable {
private String name;

public User() {

}

protected String getName() {
return this.name;
}

protected void setName(String name) {
this.name = name;
}

}




package com.example.commitTest.client;

import com.extjs.gxt.ui.client.data.BeanModelMarker;
import com.extjs.gxt.ui.client.data.BeanModelMarker.BEAN;

@BEAN(com.example.commitTest.client.User.class)
public interface UserBeanModel extends BeanModelMarker {
}





package com.example.commitTest.client;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelFactory;
import com.extjs.gxt.ui.client.data.BeanModelLookup;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.MemoryProxy;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.Record;
import com.extjs.gxt.ui.client.widget.Info;
import com.google.gwt.core.client.EntryPoint;

public class AppEntryPoint implements EntryPoint {

public void onModuleLoad() {

final User user = new User();
user.setName("bob");

List<User> userList = new ArrayList<User>(1);
userList.add(user);

BeanModelFactory userFactory = BeanModelLookup.get().getFactory(User.class);
final ListLoader loader = new BaseListLoader(new MemoryProxy<List<User>>(userList), new BeanModelReader());

final ListStore<ModelData> store = new ListStore<ModelData>(loader);
store.setMonitorChanges(true);
loader.load();

final Record rec = store.getRecord(store.getAt(0));
rec.beginEdit();
BeanModel model = (BeanModel) store.getAt(0);
rec.set("name", "jim");
rec.cancelEdit(); /// doesn't seem to change anything. record is still updated

model = (BeanModel) store.getAt(0);
User u2 = ((User)model.getBean());
if(u2.getName() != "bob") {
Info.display("fail1", "rec.cancelEdit did not roll back: " + u2.getName() );
}

((User)model.getBean()).setName("jim");
store.rejectChanges();

u2.setName("smith");
u2 = ((User)model.getBean());
if(u2.getName() != "bob") {
Info.display("fail2", "store.rejectChanges did not roll back: " + u2.getName() );
}

Info.display("done", null);
}
}

sven
19 May 2009, 6:35 AM
There is an issue in M1 that is already fixed in SVN

brendand
19 May 2009, 1:25 PM
Do you have a time frame for opening up access to M2? If I was to purchase a "Commercial License (including full source code)", would that source code be M2?

sven
19 May 2009, 1:27 PM
No. If you have a support subscription you would have access to SVN. M2 is not yet released

brendand
19 May 2009, 1:28 PM
Do you have an estimate of when you'll be releasing M2?

brendand
19 May 2009, 5:10 PM
There is an issue in M1 that is already fixed in SVN

Is it possible to get read only access to your issue tracking system. Might save me (and others) from spending 10 hours tracking down an issue that is already known about, and solved.