GWT - 实现用于登录目的的DialogBox [英] GWT - Implementing a DialogBox for Login purposes
问题描述
这里是uibinder文件:
$ b $为了测试目的,我想使用DialogBox来登录到我的应用程序。 b
<!DOCTYPE ui:UiBinder SYSTEMhttp://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:标签>使用者名称< / g:标签>
< g:TextBox ui:field =username>< / g:TextBox>
< g:标签>密码< / g:标签>
< g:PasswordTextBox ui:field =password>< / g:PasswordTextBox>
< g:按钮ui:field =登录>登录< / g:按钮>
< / g:HTMLPanel>
< / ui:UiBinder>
以下是我的实现:
public class Login extends DialogBox {
private static LoginUiBinder uiBinder = GWT.create(LoginUiBinder.class);
接口LoginUiBinder扩展了UiBinder< Widget,Login> {}
@UiField
TextBox用户名;
@UiField
PasswordTextBox密码;
@UiField
按钮登录;
public Login(){
setHTML(Login);
setWidget(uiBinder.createAndBindUi(this));
$ / code>
现在我的问题是:这是正确的方法做它?该文档似乎没有说如何做这种事情......
这就是我所做的,并且它在生产中已经工作了好几个月。
我用抽象方法 onConfirm
和一个内置的确认按钮。我还在UiBinder中包含一个接受小部件的面板,并覆盖setWidget函数以将小部件放入该内部面板。然后,每当我需要一个新的对话框时,我可以写:
最后CustomWidget无论哪个WidgetINeedRightNow = xyz;
CustomDialog dialog = new CustomDialog()
{
@Override
protected void onConfirm()
{
process(whicheverWidgetINeedRightNow.getData());
}
};
dialog.setWidget(whicheverWidgetINeedRightNow);
模板UiBinder中的ok按钮被硬连线以在按下时调用onConfirm。漂亮!对于更复杂的情况,我会在自己命名的类中继承CustomDialog。
在我的应用程序的5或6种不同情况下,不必重新设计或重新编码任何东西。
For testing purposes, I want to use a DialogBox for logging into my application.
Here's 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's my implementation of it:
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 correct way to do it? The documentation doesn't seem to say anything on how to do this sort of thing...
That's what I do, and it's been working great in production for months. It's super easy to understand and reuse.
I made an abstract dialog with the same pattern that has an abstract method onConfirm
and a built-in confirm button. I also include in the UiBinder a panel to accept a widget, and override the setWidget function to put the widget into that interior panel. Then, whenever I need a new dialog for something, I can just write:
final CustomWidget whicheverWidgetINeedRightNow = xyz;
CustomDialog dialog = new CustomDialog()
{
@Override
protected void onConfirm()
{
process(whicheverWidgetINeedRightNow.getData());
}
};
dialog.setWidget(whicheverWidgetINeedRightNow);
The ok button in the template UiBinder is hard-wired to call onConfirm when it's pressed. Nifty! For more complex cases, I'd subclass CustomDialog in its own named class.
It's worked well for me in maybe 5 or 6 different situations in my app, and I don't have to re-style or re-code anything.
这篇关于GWT - 实现用于登录目的的DialogBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!