Monday, March 26, 2012

RequestFactoryEditorDriver remains dirty

I followed the Editor example using RequestFactoryEditorDriver for RF-driven persistence. But it doesn't work for me. 

When I call 

public class EmployeeEditor extends Composite implements Editor<EmployeeProxy> 

the model data is transfered into the Composite and all UiBinder fields get their values. 

I use this code 

    void edit(EmployeeProxy employee) {
        driver.initialize(cf.getRF(), employeeEditor);
        final EmployeeReqCtx reqCtx = cf.getRF().employeeReqCtx();
        driver.edit(employee, reqCtx);

        cf.getLogger().log(Level.INFO, "driver.isDirty: " + driver.isDirty());
    }

to achieve this.The driver

interface Driver extends RequestFactoryEditorDriver<EmployeeProxy, EmployeeEditor> 

is clean at this point. As soon as I call

    void save() {
        cf.getLogger().log(Level.INFO, "driver.isDirty: " + driver.isDirty());
        final RequestContext reqCtx = driver.flush();
        if (driver.hasErrors()) {
            cf.getLogger().log(Level.INFO, "DRIVER HAS ERRORS.");
        }
        cf.getLogger().log(Level.INFO, "driver.isDirty: " + driver.isDirty());


        // Send the request
        reqCtx.fire(new Receiver<Void>() {
            @Override
            public void onConstraintViolation(Set<ConstraintViolation<?>> errors) {
                cf.getLogger().log(Level.SEVERE, "ERRORS DETECTED ON THE SERVER" + errors.size());
            }

            @Override
            public void onSuccess(Void response) {
                cf.getLogger().log(Level.SEVERE, "SUCCESS!");
                cf.getLogger().log(Level.INFO, "driver.isDirty: " + driver.isDirty());
            }
        });
        cf.getLogger().log(Level.INFO, "driver.isDirty: " + driver.isDirty());
    }

the driver becomes dirty and the "SUCCESS!" message appears. So the entity has been persisted at this point? However the subsequent log message in onSuccess() reports that the driver is still dirty. And when I call save() again, the 

Caused by: java.lang.IllegalStateException: A request is already in progress

exception is thrown.

My persistence framework is Objectify and the corresponding RequestFactory using JUnit tests are working and modify the entities as expected.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/B7S4AZxrvgMJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment