Handling parameters between pages in Navigator 7

Hi!!,

I’m trying to make a example with Vaadin 6 and Navigator 7-7.49 version. I thought it was an easy one but I’m stuck :(. I have 2 page, say PageA and PageB. What I want is passed one parameter from PageA to PageB. When these parameters are primitives types there is no problem. The problem is when the parameters are non-primitive types. Here is my code for PageA:


import java.util.Date;

import org.vaadin.navigator7.NavigableApplication;
import org.vaadin.navigator7.Page;
import org.vaadin.navigator7.ParamPageLink;
import org.vaadin.navigator7.interceptor.Interceptor;
import org.vaadin.navigator7.interceptor.PageInvocation;

import com.hopcroft.vaadin.pojo.MyPojo;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
@Page()
public class SimpleContentPage extends VerticalLayout implements Interceptor {

	public SimpleContentPage() {
		addComponent(new Label("This is page 1"));
		ParamPageLink paramPageLink = new ParamPageLink("Go to page 2:", SimpleContentPageTwo.class);
		paramPageLink.addParam("id", 23);
		paramPageLink.addParam("myPojo", getMyPojo());
		addComponent(paramPageLink);

	}

	private MyPojo getMyPojo() {
		final MyPojo myPojo = new MyPojo();
		myPojo.setNombre("myPojo name");
		myPojo.setInicio(new Date());
		myPojo.setFin(new Date());
		myPojo.setId(1L);
		return myPojo;
	}
}

… and for PageB:


import org.vaadin.navigator7.NavigableApplication;
import org.vaadin.navigator7.Navigator.NavigationEvent;
import org.vaadin.navigator7.Page;
import org.vaadin.navigator7.ParamChangeListener;
import org.vaadin.navigator7.WebApplication;
import org.vaadin.navigator7.interceptor.Interceptor;
import org.vaadin.navigator7.interceptor.PageInvocation;
import org.vaadin.navigator7.uri.EntityUriAnalyzer;
import org.vaadin.navigator7.uri.Param;

import com.hopcroft.vaadin.commons.MyUriAnalizer;
import com.hopcroft.vaadin.pojo.MyPojo;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
@Page
public class SimpleContentPageTwo extends VerticalLayout implements ParamChangeListener, Interceptor {

	// class parameters.
	@Param(name = "id", required = true)
	int id;
	@Param(name = "myPojo", required = true)
	MyPojo myPojo;

	// class atributes.
	Label label;

	public SimpleContentPageTwo() {
		addComponent(new Label("This is page 2"));
		label = new Label();
		addComponent(label);
	}

	public void paramChanged(NavigationEvent navigationEvent) {
		System.out.println(">paramChanged method");
	}

	public void intercept(PageInvocation pageInvocation) {
		System.out.println(">intercept method");

	}

}

When I execute this code Vaadin (I think is Navigator7 indeed) shows me a notification about a conversion problem occurred. You can see the notification in the attachment file.

I don’t know exactly what this problem means but I’ve tried to fix it. What I’ve done is as follows:

  • Creating my own uriAnalyzer class.

public class MyUriAnalizer extends EntityUriAnalyzer<BaseEntity> {

	@Override
	public BaseEntity findEntity(Class<? extends BaseEntity> entityClass, String pk) {
               return ??;
	}

	@Override
	public String getEntityFragmentValue(BaseEntity entity) {
		return entity.getId().toString();

	}

}

Now when I execute my code I have:

  • Before rendering my PageA, there is a call to getEntityFragmentValue. The entity value is equal to the MyPojo value within PageA, so what I return is the MyPojo id.
  • The PageA is rendered in a correct way.
  • After clicking the link labeled as ‘"Go to page 2:’ MyUriAnalyzer intercepts the click event and it calls the findEntity method. Here is the problem. How can I access to MyPojo that is within the PageA (MyPojo is not attached to any DB table)??. I’ve read that the findEntity method is used when you want to use JPA / Hibernate support because you have in the pk parameter the identifier that you need in order to use in your HQL query or whatever. But what if you don’t want to call the DB.
    Imagine you have a form in pageA with some fields generated as you previously attached a BeanItem in the setItemDataSource method. And before commit this form to your database, you want to show the user a second page asking if he or she is sure about storing the data. That data (the form) is not in your database yet but inside your pageB. How could I show the form fields values in my PageB?.

I know that I can save my parameter as data in my NavigableApplication


		NavigableApplication.getCurrentNavigableAppLevelWindow().setData(getMyPojo());

But the problems are:

  • I don’t want to do this way. I prefer to stored my data as a parameter instead as data in my application.
  • Where should I call this code in order to get myPojo value from pageA?

I do know that I’m a little bit lost but if someone can help me I’d be grateful.

Iván.
11853.png