Gwt-platform with UiBinder and UiEditors Framework (GWT Editors) -
i struggle editor framework of gwt. because documentation lame- no hurt feelings- saying.
now have problem cannot execute button event on editor. error:
uncaught com.google.gwt.event.shared.umbrellaexception: exception caught: (typeerror) : cannot read property 'onloginbuttonclick_3_g$' of undefined
i not sure doing wrong. didn't found example of that. hope help.
here code:
editor
public class logineditor extends viewwithuihandlers<logineditoruihandlers> implements editor<loginmodel> { private verticalpanel widget = new verticalpanel(); materialtextbox email = new materialtextbox(); materialtextbox password = new materialtextbox(); materialbutton btnlogin = new materialbutton(); public logineditor() { initwidget(widget); email.setplaceholder("e-mail"); password.setplaceholder("password"); btnlogin.settext("login"); btnlogin.addclickhandler(new clickhandler() { @override public void onclick(clickevent event) { onloginbuttonclick(event); } }); widget.add(email); widget.add(password); widget.add(btnlogin); } void onloginbuttonclick(clickevent e){ getuihandlers().onloginbuttonclick(); window.alert("test"); } }
presenter
public class loginpresenter extends presenter<loginpresenter.myview, loginpresenter.myproxy> implements logineditoruihandlers { public interface myview extends view , hasuihandlers<logineditoruihandlers> {} public static final type<revealcontenthandler<?>> slot_login = new type<revealcontenthandler<?>>(); @proxystandard @nametoken(nametokens.login) public interface myproxy extends proxyplace<loginpresenter> {} // editor interface driver extends simplebeaneditordriver<loginmodel, logineditor> {} private static final loginservice service = gwt.create(loginservice.class); driver editordriver = gwt.create(driver.class); private loginmodel model = new loginmodel("email","pass"); private logineditor editor = new logineditor(); @override public void onloginbuttonclick() { materialtoast.firetoast("test"); try{ system.out.println(editordriver == null); system.out.println(editordriver.isdirty()); editordriver.isdirty(); } catch (nullpointerexception e) { materialtoast.firetoast("null: " + e.getlocalizedmessage()); } if (editordriver.isdirty()) { model = editordriver.flush(); if (editordriver.haserrors()) { stringbuilder errorbuilder = new stringbuilder(); (editorerror error : editordriver.geterrors()) { errorbuilder.append(error.getmessage() + "\n"); } materialtoast.firetoast(errorbuilder.tostring()); } else { service.login( model, new methodcallback<integer>() { @override public void onsuccess(method method, integer response) { materialtoast.firetoast("succefully set info. status code: " + response); } @override public void onfailure(method method, throwable exception) { materialtoast.firetoast("error setting"); } }); } } else { materialtoast.firetoast("data has not changed"); } } @inject loginpresenter( eventbus eventbus, myview view, myproxy proxy) { super(eventbus, view, proxy, revealtype.root); editordriver.initialize(editor); editordriver.edit(model); getview().setuihandlers(this); } }
view
public class loginview extends viewwithuihandlers<logineditoruihandlers> implements loginpresenter.myview { interface binder extends uibinder<widget, loginview> { } @inject loginview(binder uibinder) { initwidget(uibinder.createandbindui(this)); } }
view.ui.xml
<m:materialrow ui:field="loginwidget"> <m:materialcolumn grid="s12 m4 l4" offset="l4" > <m:materialtitle title="login" description="please provide account credentials."/> <m:materialpanel padding="5" shadow="1" addstylenames="{style.panel}"> <m:materialpanel addstylenames="{style.fieldpanel}"> <e:logineditor></e:logineditor> </m:materialpanel> </m:materialpanel> </m:materialcolumn> </m:materialrow>
uihandlers
interface logineditoruihandlers extends uihandlers { void onloginbuttonclick(); } interface loginuihandlers extends uihandlers { }
here working solution:
presenter
package pl.korbeldaniel.cms.client.login; import java.util.arraylist; import java.util.set; import javax.validation.constraintviolation; import javax.validation.validation; import javax.validation.validator; import org.fusesource.restygwt.client.method; import org.fusesource.restygwt.client.methodcallback; import gwt.material.design.client.ui.materialtoast; import com.google.gwt.core.shared.gwt; import com.google.gwt.editor.client.editorerror; import com.google.gwt.editor.client.simplebeaneditordriver; import com.google.gwt.event.shared.gwtevent.type; import com.google.gwt.user.client.ui.label; import com.google.gwt.user.client.ui.rootpanel; import com.google.inject.inject; import com.google.web.bindery.event.shared.eventbus; import com.gwtplatform.mvp.client.presenter; import com.gwtplatform.mvp.client.annotations.proxystandard; import com.gwtplatform.mvp.client.proxy.proxyplace; import com.gwtplatform.mvp.client.annotations.nametoken; import com.gwtplatform.mvp.client.proxy.revealcontenthandler; import com.gwtplatform.mvp.client.hasuihandlers; import pl.korbeldaniel.cms.client.editor.beaneditview; import pl.korbeldaniel.cms.client.model.loginmodel; import pl.korbeldaniel.cms.client.place.nametokens; import pl.korbeldaniel.cms.client.service.loginservice; public class loginpresenter extends presenter<loginpresenter.myview, loginpresenter.myproxy> implements loginuihandlers { public interface myview extends beaneditview<loginmodel>, hasuihandlers<loginuihandlers> {} public static final type<revealcontenthandler<?>> slot_login = new type<revealcontenthandler<?>>(); @proxystandard @nametoken(nametokens.login) public interface myproxy extends proxyplace<loginpresenter> {} // editor private simplebeaneditordriver<loginmodel, ?> editordriver; private static final loginservice service = gwt.create(loginservice.class); private loginmodel model = new loginmodel("",""); @override public void onloginbuttonclick() { string msg = "user pressed button."; gwt.log(msg); if (editordriver.isdirty()) { model = editordriver.flush(); validatemodel(); gwt.log(string.valueof(editordriver.haserrors())); if (editordriver.haserrors()) { materialtoast.firetoast("errors occur"); stringbuilder errorbuilder = new stringbuilder(); (editorerror error : editordriver.geterrors()) { gwt.log(error.getmessage()); errorbuilder.append(error.getmessage() + "\n"); } //materialtoast.firetoast(errorbuilder.tostring()); rootpanel.get().add(new label(errorbuilder.tostring())); } else { service.login( model, new methodcallback<integer>() { @override public void onsuccess(method method, integer response) { materialtoast.firetoast("succefully set info. status code: " + response); } @override public void onfailure(method method, throwable exception) { materialtoast.firetoast("error setting"); } }); } } else { materialtoast.firetoast("data has not changed"); } } private void validatemodel() { validator validator = validation.builddefaultvalidatorfactory().getvalidator(); set<constraintviolation<loginmodel>> violations = validator.validate(model); gwt.log(string.valueof(violations.size())); if (violations.size() > 0) { editordriver.setconstraintviolations(new arraylist<constraintviolation<?>>(violations)); } } @inject loginpresenter(eventbus eventbus,myview view, myproxy proxy) { super(eventbus, view, proxy, revealtype.root); getview().setuihandlers(this); editordriver = getview().createeditordriver(); editordriver.edit(model); } }
view/editor
package pl.korbeldaniel.cms.client.login; import gwt.material.design.client.ui.materialbutton; import gwt.material.design.client.ui.materialcheckbox; import gwt.material.design.client.ui.materialtextbox; import javax.inject.inject; import pl.korbeldaniel.cms.client.model.loginmodel; import com.google.gwt.core.client.gwt; import com.google.gwt.editor.client.simplebeaneditordriver; import com.google.gwt.event.dom.client.clickevent; import com.google.gwt.event.dom.client.clickhandler; import com.google.gwt.uibinder.client.uibinder; import com.google.gwt.uibinder.client.uifield; import com.google.gwt.user.client.ui.widget; import com.gwtplatform.mvp.client.viewwithuihandlers; public class loginview extends viewwithuihandlers<loginuihandlers> implements loginpresenter.myview { interface binder extends uibinder<widget, loginview> {} /** driver link proxy bean view. */ public interface editordriver extends simplebeaneditordriver<loginmodel, loginview> { } @uifield materialtextbox email; @uifield materialtextbox password; @uifield materialbutton loginbutton; @uifield materialcheckbox keepmeloggedincheckbox; @inject loginview(binder uibinder) { initwidget(uibinder.createandbindui(this)); addclickhandlertologinbutton(); } //@uihandler("loginbutton") private void onloginbuttonclick(clickevent e){ getuihandlers().onloginbuttonclick(); } private void addclickhandlertologinbutton() { loginbutton.addclickhandler(new clickhandler() { @override public void onclick(clickevent event) { onloginbuttonclick(event); } }); } @override public simplebeaneditordriver<loginmodel, ?> createeditordriver() { editordriver driver = gwt.create(editordriver.class); driver.initialize(this); return driver; } }
validatorfactory
package pl.korbeldaniel.cms.client.login; import javax.validation.validator; import pl.korbeldaniel.cms.client.model.loginmodel; import com.google.gwt.core.client.gwt; import com.google.gwt.validation.client.abstractgwtvalidatorfactory; import com.google.gwt.validation.client.gwtvalidation; import com.google.gwt.validation.client.impl.abstractgwtvalidator; public final class samplevalidatorfactory extends abstractgwtvalidatorfactory { /** * validator marker validation sample project. classes , * groups listed in {@link gwtvalidation} annotation can validated. */ @gwtvalidation(loginmodel.class) public interface gwtvalidator extends validator { } @override public abstractgwtvalidator createvalidator() { return gwt.create(gwtvalidator.class); } }
uihandlers
package pl.korbeldaniel.cms.client.login; import com.gwtplatform.mvp.client.uihandlers; interface loginuihandlers extends uihandlers { void onloginbuttonclick(); }
bean edit view interface
package pl.korbeldaniel.cms.client.editor; import com.google.gwt.editor.client.editor; import com.google.gwt.editor.client.simplebeaneditordriver; import com.gwtplatform.mvp.client.view; /** * implemented views edit beans. * * @param <b> type of bean */ public interface beaneditview<b> extends view, editor<b> { /** * @return new {@link simplebeaneditordriver} initialized run editor */ simplebeaneditordriver<b, ?> createeditordriver(); }
i hope one.
Comments
Post a Comment