在我的 Vaadin 应用程序中,我有一个CustomLayout
带有文本字段的面板:
public class BookkeepingView extends VerticalLayout implements View {
private TextField userName;
private PasswordField password;
public BookkeepingView()
{
VerticalLayout contentPanel = new VerticalLayout();
contentPanel.setStyleName("body");
contentPanel.addComponent(getHeaderPanel());
contentPanel.addComponent(getLoginPanel());
contentPanel.addComponent(getFooterPanel());
addComponent(contentPanel);
}
[...]
private CustomLayout getLoginPanel() {
Panel panel = new Panel();
panel.setSizeUndefined();
addComponent(panel);
CustomLayout customLayoutPanel = new CustomLayout("login");
userName = new TextField();
userName.setImmediate(true);
customLayoutPanel.addComponent(userName, "j_username");
当我在文本字段中输入文本时userName
,按下带有如下所示事件处理程序的按钮,我得到一个空的用户名(托盘通知包含文本User name:
)。
private void loginButtonPressed() {
String userName = this.userName.getValue();
Notification.show("User name:" + userName, Notification.Type.TRAY_NOTIFICATION);
}
如何修改代码,以便我可以从 a 中的userName
文本字段中读取用户输入的值CustomLayout
(我需要CustomLayout
以便轻松自定义应用程序的外观)?
更新 1 (06.11.2013 18:16 MSK):
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.ui.*;
public class BookkeepingView extends VerticalLayout implements View {
private TextField userName;
private PasswordField password;
public BookkeepingView()
{
VerticalLayout contentPanel = new VerticalLayout();
contentPanel.setStyleName("body");
contentPanel.addComponent(getHeaderPanel());
contentPanel.addComponent(getLoginPanel());
contentPanel.addComponent(getFooterPanel());
addComponent(contentPanel);
}
private Component getHeaderPanel() {
return createCustomLayoutPanel("main-navigation");
}
private Component getFooterPanel() {
return createCustomLayoutPanel("copyright");
}
private CustomLayout getLoginPanel() {
Panel panel = new Panel();
panel.setSizeUndefined();
addComponent(panel);
CustomLayout customLayoutPanel = new CustomLayout("login");
userName = new TextField();
userName.setImmediate(true);
customLayoutPanel.addComponent(userName, "j_username");
password = new PasswordField();
customLayoutPanel.addComponent(password, "j_password");
final Button loginButton = new Button(I18n.l("bookkeeping_login_button"));
customLayoutPanel.addComponent(loginButton, "login");
loginButton.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent clickEvent) {
loginButtonPressed();
}
});
return customLayoutPanel;
}
private void loginButtonPressed() {
String userName = this.userName.getValue();
Notification.show("User name:" + userName, Notification.Type.TRAY_NOTIFICATION);
}
private CustomLayout createCustomLayoutPanel(final String aHtmlFileName) {
Panel panel = new Panel();
panel.setSizeUndefined();
addComponent(panel);
CustomLayout customLayoutPanel = new CustomLayout(aHtmlFileName);
return customLayoutPanel;
}
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
}
}