GWT - implementation of DialogBox function for login

For testing purposes, I want to use DialogBox to enter my application.

Here is the uibinder file:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui"> <ui:style> </ui:style> <g:HTMLPanel> <g:Label>Username</g:Label> <g:TextBox ui:field="username"></g:TextBox> <g:Label>Password</g:Label> <g:PasswordTextBox ui:field="password"></g:PasswordTextBox> <g:Button ui:field="login">Login</g:Button> </g:HTMLPanel> </ui:UiBinder> 

And here is my implementation:

 public class Login extends DialogBox { private static LoginUiBinder uiBinder = GWT.create(LoginUiBinder.class); interface LoginUiBinder extends UiBinder<Widget, Login> {} @UiField TextBox username; @UiField PasswordTextBox password; @UiField Button login; public Login() { setHTML("Login"); setWidget(uiBinder.createAndBindUi(this)); } } 

Now my question is: is this the right way to do this? The documentation does not seem to say anything about how to do this ...

+4
source share
1 answer

This is what I am doing and it has been working perfectly in production for several months. It is super easy to understand and reuse.

I created an abstract dialog with the same template that has an onConfirm abstract method and a built-in confirmation button. I also include a panel in the UiBinder panel to accept the widget and override the setWidget function to place the widget in this internal panel. Then, when I need a new dialog box for something, I can simply write:

 final CustomWidget whicheverWidgetINeedRightNow = xyz; CustomDialog dialog = new CustomDialog() { @Override protected void onConfirm() { process(whicheverWidgetINeedRightNow.getData()); } }; dialog.setWidget(whicheverWidgetINeedRightNow); 

The ok button in the UiBinder template is rigidly connected to the OnConfirm call when pressed. Sharpness! For more complex cases, I would subclass CustomDialog in my own named class.

It worked well for me, perhaps in 5 or 6 different situations in my application, and I do not need to rewrite or transcode anything.

+6
source

Source: https://habr.com/ru/post/1345691/


All Articles