Thursday, June 2, 2011

Strange bug with Editor and context.create() (With code example)

When submitting RequestContext with a new EntityProxy I get error
Autobean is frozen but when editing an existing proxy no error. I also
get two EntityChangeEvent's when submitting the context for the newly
created entity.


So I have searched for a while and I believe this may be an issue with
having a ValueListBox subeditor and creating a new EntityProxy. I have
two functions that use the same editor. I have tried multiple things
including making sure I am not reusing EditorDriver, Editor or
RequestContext.


15:13:51.332 [ERROR] [virtualFactory] Uncaught exception escaped
java.lang.IllegalStateException: The AutoBean has been frozen
at
com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.checkFrozen(AbstractAutoBean.java:
195)
at
com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.setProperty(AbstractAutoBean.java:
270)
at sun.reflect.GeneratedMethodAccessor524.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
43)
at java.lang.reflect.Method.invoke(Method.java:613)
at
com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at
com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at
com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:
167)


/** This function throws Autobean frozen exeption and I see two
EntitiProxyChange events when this fires.
The function is successful though but I am wondering if there is
something I am doing wrong
*/
private void showAddAccountView() {
UserEditor editor = new UserEditor();
UserEditorDriver driver = GWT.create(UserEditorDriver.class);

driver.initialize(editor);
editor.setDriver(driver);
UserRequest request =
clientFactory.daoRequestFactory().userRequest();
UserProxy editable =
request.edit(request.create(UserProxy.class));
request.saveAndReturn(editable).with(driver.getPaths());
driver.edit(editable, request);

DialogBox db = new DialogBox();
db.setAutoHideEnabled(true);
db.setAnimationEnabled(true);
db.setGlassEnabled(true);
db.setWidget(editor);
db.center();
}

/** This function has no problems when firing context as it is editing
an already created EntitiyProxy */

private void onAccountSelected(SelectionChangeEvent event) {
UserEditor editor = new UserEditor();
UserEditorDriver driver = GWT.create(UserEditorDriver.class);

driver.initialize(editor);
editor.setDriver(driver);
UserRequest request =
clientFactory.daoRequestFactory().userRequest();
UserProxy editable =
request.edit(selectionModel.getSelectedObject());
request.saveAndReturn(editable).with(driver.getPaths());
driver.edit(editable, request);

accountEditorPanel.setWidget(editor);
}


---------------
Editor View.
----------------

public class UserEditor extends Composite implements Editor<UserProxy>
{

@UiTemplate("templates/UserEditor.ui.xml")
interface Binder extends UiBinder<Widget, UserEditor> {
}


@UiField TextBox name;
@UiField TextBox email;

@UiField (provided=true)
ValueListBox<UserRole> role = new ValueListBox<UserRole>(new
AbstractRenderer<UserRole>() {

@Override
public String render(UserRole object) {
return object == null ? "" : object.name();
}
});

@UiField Button submit;


private RequestFactoryEditorDriver<UserProxy, UserEditor> driver;


public UserEditor() {

initWidget(GWT.<Binder>create(Binder.class).createAndBindUi(this));

role.setAcceptableValues(Arrays.asList(UserRole.values()));
}

@UiHandler("submit")
void onClick(ClickEvent event) {
UserRequest request = (UserRequest) driver.flush();

// Check for errors
if (driver.hasErrors()) {
List<EditorError> errors = driver.getErrors();
for (EditorError error : errors) {
Logger.getLogger("UserEditor").info("Errors occurred in
user editor" + error.getMessage());
}
return;
}

request.fire();
}

public void setDriver(RequestFactoryEditorDriver<UserProxy,
UserEditor> driver) {
this.driver = driver;
}
}


Thank you in advance for your assistance.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
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