Hi everybody,
I want to start the development of a new webapp using Vaadin 7, but I have some problems using views. I started from one of Nicolas’ articles (http://morevaadin.com/content/windows-switching-vaadin-7), but I don’t understand how to walk the user between views (as it’s the case with pages in a standard webapp).
If somebody can point me to a real/complete example that would be very good.
For example, I started using a simple case like this one:
@SuppressWarnings("serial")
public class MyRoot extends Root {
LoginView loginView;
MainView mainView;
@Override
public void init(WrappedRequest request) {
setCaption("MyRoot");
String categ = request.getParameter("categ");
if (categ == null) {
if (loginView == null)
loginView = new LoginView();
setContent(loginView);
} else {
if (mainView == null)
mainView = new MainView("anonymous", categ);
setContent(mainView);
}
}
}
and the LoginView class is:
@SuppressWarnings("serial")
public class LoginView extends CustomComponent {
private TextField login = new TextField("Login");
private TextField password = new TextField("Password");
public LoginView() {
FormLayout layout = new FormLayout();
setCompositionRoot(layout);
layout.addComponent(login);
layout.addComponent(password);
Button button = new Button("Login");
layout.addComponent(button);
button.addListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
//getApplication().getMainWindow().setContent(new MainView()); <-- this doesn't work as getMainWindow() is undefined
Root.getCurrentRoot().setContent(new MainView(login.getValue(), "no-categ"));
}
});
}
}
and the MainView class is another CustomComponent, a simple one anyway.
So, having this, http://localhost:8080/vedas request gets me to the LoginView, and http://localhost:8080/vedas?categ=something request gets me to the MainView. This is fine!
But getting to the LoginView and simulating the login process, first click on Login button does nothing (at least on the client side) and the second click generates a NPE.
This is the what is thrown on stdout:
Apr 28, 2012 6:07:39 PM com.vaadin.Application terminalError
SEVERE: Terminal error:
java.lang.NullPointerException
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleBurst(AbstractCommunicationManager.java:1415)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1355)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleUidlRequest(AbstractCommunicationManager.java:561)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:506)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:409)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
…
I also used for this example one of the Vaadin 7 mini tutorials found here: https://vaadin.com/wiki/-/wiki/Main/Finding%20the%20current%20Root%20and%20Application
Any help is really appreciated!
PS.
Maybe environment used can be useful? I am using Vaadin 7 alpha2 with Tomcat 7.0.27 on a Win7 platform.
Thank you.