so, just wondering if this is even possible
i have been using the editor framework and am wondering if, instead of pushing the state of the object out to the ui using the edit calls – is there anyway you can take the state of the form and pump it into the object.
i am using a RequestFactoryEditorDriver with proxy objects and am trying to do something along the lines of a reverse-editor where i populate my proxy object with the values in the form and then persist it.
I am also new to GWT, i started 2 weeks ago and have been teaching myself off of various sample code and google, is there any other GWT framework to do this. or, what are the best practices when simply persisting new objects?
i am using activities/places and up until just tonight (i am trying to get something out quick so i know it wasn’t the correct way to do it) was passing in all the fields of the form through my presenter to create an object. i would like to do something cleaner.
any help is greatly appreciated
to anybody else doing this – thomas broyer answered it and here is how i got this
activity to work
public class EmployeesCreateFormActivity extends AbstractActivity implements EmployeesCreateFormView.Presenter
interface EmployeeEditorDriver extends RequestFactoryEditorDriver<EmployeeProxy, EmployeesCreateFormView> {
}
private final ClientFactory clientFactory;
private final EmployeesCreateFormView view;
private EmployeeRequestContext employeeContext;
private EmployeeProxy employee;
private final EmployeeEditorDriver editor;
public EmployeesCreateFormActivity(ClientFactory clientFactory) {
this.clientFactory = clientFactory;
view = clientFactory.getEmployeesCreateFormView();
employeeContext = clientFactory.getRequestFactory().employeeContext();
employee = employeeContext.create(EmployeeProxy.class);
editor = GWT.create(EmployeeEditorDriver.class);
}
@Override
public void start(AcceptsOneWidget container, EventBus eventBus) {
view.setPresenter(this);
container.setWidget(view.asWidget());
editor.initialize(view);
editor.edit(employee, employeeContext);
}
@Override
public void doCreate() {
editor.flush();
// I STILL HAVE NO IDEA WHAT TO DO WITH THIS ????????
employee.setVersion(Integer.valueOf(1));
Request<EmployeeProxy> createRequest = employeeContext.persist(employee);
createRequest.fire(new Receiver<EmployeeProxy>() {
@Override
public void onSuccess(EmployeeProxy response) {
Window.alert("successfully created employee " + response.getId() + ": " + response.getFirstName());
clientFactory.getPlaceController().goTo(new EmployeesCreatePlace());
}
});
}
});
}
The way to do it is to
edit()an empty object (e.g. one that you just created) when your activity starts (just like if you were editing an existing object), so that theflush()will populate the object with the fields’ values.