*/
public class FormDisplayController {
public FormDisplayController(RootPanel formInfo, final RootPanel formDisplay) {
EventBus eventBus = CommonGlobals.getInstance().getEventBus();
FormBuilderService server = FormBuilderGlobals.getInstance().getService();
FormEncodingFactory.register(FormEncodingClientFactory.getEncoder(), FormEncodingClientFactory.getDecoder());
try {
final String innerJson = formInfo.getElement().getInnerHTML();
formInfo.getElement().setInnerHTML("");
formInfo.getElement().getStyle().setHeight(1, Unit.PX);
eventBus.addHandler(RepresentationFactoryPopulatedEvent.TYPE, new RepresentationFactoryPopulatedHandler() {
@Override
public void onEvent(RepresentationFactoryPopulatedEvent event) {
try {
JsonLoadInput input = JsonLoadInput.parse(innerJson);
if (input != null && input.getForm() != null) {
FBForm formUI = new FBForm();
formUI.populate(input.getForm());
formDisplay.add(formUI.asFormPanel(input.getFormData()));
}
} catch (FormEncodingException e) {
Window.alert("Couldn't interpretate form: " + e.getMessage());
GWT.log("Couldn't interpretate form", e);
} catch (FormBuilderException e) {
Window.alert("Couldn't populate display: " + e.getMessage());
GWT.log("Couldn't populate display", e);
}
}
});
server.populateRepresentationFactory();
} catch (FormBuilderException e) {
Window.alert("Couldn't populate representation factory: " + e.getMessage());
GWT.log("Couldn't populate representation factory", e);
}
}