Vaadin 7 moving between views

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.

OK, me again.
I solved the issue! :slight_smile:
I just didn’t use the FragmentChangedLister, as described in
Using URI fragments
mini tutorial.
If someone else is interested I can provide a simple example: first access goes the user to the login view, if the right user is provided, the main view is provided. Otherwise, a simple notification is sent.

Hi, i’m facing the same problem as u described and using vaadin 7 alpha 2. And i read through the mini tutorial, but still i cant get it why i cant just swap my component without using the uri fragment change? and can u show me an example how to get through this Thanks.

You can swap the view from any event triggered by the user. The point with using the FragmentChangedListener is just that it helps you keep the fragment and the active view in sync so that the user will come back to the same view if opening the same URL.

You should also note that we are currently designing and implementing functionality to Vaadin 7 for automatically mapping different URI fragments to different Views which should make the explicit use of a FragmentChangedListener unnecessary. More information on this will come when we release Vaadin 7.0.0 alpha 3.