Navigating with Toolkit productivity tools or without

I have only three pages (view u can say) like mainView—>companyEditor–1–>staffview----->Staffeditor OR mainView—>companyEditor–2–>productView----->ProductEditor. If I go to staffView I always need a company as an argument in constructor and if I edit company’s product I need a company as a parameter in constructor. TPT uses and needs default constructors and then my code at the moment is useless. Can I use TPT or is there some other way to return to mainView from staffView or productView?

Thanks!
Sami

Unfortunately I haven’t used TPT personally, so I can’t help you with that, other than if you can get a hold of the created object after it has been created, you could design your views in such a way that the constructor doesn’t finalize the view, but you inject the required objects with a setter. You then call the setter from the previous view (or some central place, if you prefer), and only after you have all the required data, you finish the view.

But another way might be to use the
ThreadLocal pattern
. It’s in essence a Vaadin-suitable singleton pattern. You have a private static field in your application (private static final ThreadLocal currentApplication = new ThreadLocal()) into which you inject the application instance at the beginning of each transaction. You can then access the instance with a static getter. Since ThreadLocal is, by definition, thread safe, you can be assured that you get the correct application instance.

This way, you can store all kinds of session specific data directly to your Application instance, and retrieve it from any object whenever.