我在Vaadin和JavaEE中都很新,我有一個基本的問題,但會很樂意提供幫助。Vaadin - 在視圖間傳遞數據
我有3個班,我Vaadin項目,在這裏,他們是: 主類,只響應啓動和建立導航:
public class MyprojectUI extends UI {
public Navigator navigator;
public static final String SECOND_VIEW = "SecondView";
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = MyprojectUI.class)
public static class Servlet extends VaadinServlet {
}
@Override
protected void init(VaadinRequest request) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
ComponentContainerViewDisplay viewDisplay = new ComponentContainerViewDisplay(layout);
navigator = new Navigator(UI.getCurrent(), viewDisplay);
navigator.addView("", new FirstView());
navigator.addView(SECOND_VIEW, new SecondView());
}
}
了兩種意見類:
public class FirstView extends HorizontalLayout implements View {
TextArea text = new TextArea();
Button button = new Button("go");
@Override
public void enter(ViewChangeEvent event) {
this.addComponent(text);
this.addComponent(button);
button.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
getUI().getNavigator().navigateTo(MyprojectUI.SECOND_VIEW);
}
});
}
}
-
public class SecondView extends HorizontalLayout implements View {
Label label = new Label("Passed text here");
@Override
public void enter(ViewChangeEvent event) {
this.addComponent(label);
}
}
如何將我的TextArea中的數據傳遞給第二個視圖?當點擊「go」按鈕時,我想將標籤文本設置爲TextArea中的文本。
感謝您的幫助。