I created a a widget has a log in panel:
Here is the code:
<!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>
/* Add CSS here. See the GWT docs on UI Binder for more details */
</ui:style>
<g:VerticalPanel width="200px" height="auto">
<g:Label text="Username:" width="100%" height="auto" />
<g:TextBox ui:field="Username" width="100%" height="auto" />
<g:Label text="Password:" width="100%" height="auto"/>
<g:PasswordTextBox ui:field="Password" width="100%" height="auto" />
<g:Cell horizontalAlignment="ALIGN_RIGHT">
<g:Button text="Login" ui:field="button" height="25px"/>
</g:Cell>
</g:VerticalPanel>
</ui:UiBinder>
And here is the generated class:
public class LoginPanel extends Composite implements HasText {
private static LoginPanelUiBinder uiBinder = GWT
.create(LoginPanelUiBinder.class);
interface LoginPanelUiBinder extends UiBinder<Widget, LoginPanel> {
}
public LoginPanel() {
initWidget(uiBinder.createAndBindUi(this));
}
@UiField
Button button;
@UiField
TextBox Username;
@UiField
PasswordTextBox Password;
public LoginPanel(String firstName) {
initWidget(uiBinder.createAndBindUi(this));
}
@UiHandler("button")
void onClick(ClickEvent e) {
Window.alert("Hello!");
}
public String getUsername() {
return Username.getText();
}
public String getPassword() {
return Password.getText();
}
@Override
public String getText() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setText(String text) {
// TODO Auto-generated method stub
}
}
I want to access the click event of this class on the onModuleLoad so that I can know when the user has clicked the button and has successfully logged in, so I can call other panels I created. Only thing this does is an alert.
This is the first time I’m playing with UiBinder, so I might be missing something.
Thank you.
So you want your
LoginPanelto notify your main app class when a user has logged in?This is really a job for
EventBus. Take a look at the exact use case that you need (AuthenticatedEvent): How to use the GWT EventBus