在我的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);
}
如何修改代码,以便我可以从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) {
}
}