pass variable to view

Hi All,

I would like to know what is the best way to pass object to a view.

I want to use something like this (gwt does it) but I can not find any extra parameter in navigator:

Product product = …

Of course, I can use session for pass data from e.g. a view to another view, but I have to delete object from the session after I read it:

Product product = …
getUI().getSession().setAttribute(“product”, product);

Read data in an other view:

Product product = (Product) getUI().getSession().getAttribute(“product”);
getUI().getSession().setAttribute(“product”, null);

Could you tell me what is the best practice to do it?

Thank you.

There is no direct way to pass arbitrary parameters to a view because views should always be possible to represent as a URI. However, the parameter of Navigator.navigateTo(String) can contain a parameters part, by default separated from the view name by a slash (“/”). This parameters string can be accessed via ViewChangeEvent.getParameters(). Its content has no special meaning to the framework; the application can use it however it likes. Typically, one would pass the ID of an object to a view, then let the view fetch the object by the id.

This all has the benefit that the URIs in your application work intuitively - the user can copypaste the location URI or store it as a browser bookmark and whenever the URI is loaded, the view knows to show the relevant content.

Thank you!

If I want to pass java beans to a view I am going to use these methods:

private static final String TEMPORARY_VARIABLE = “temp”;

public static void putData(com.vaadin.ui.UI ui, Object object)
	ui.getSession().setAttribute(TEMPORARY_VARIABLE, object);

public static Object readData(com.vaadin.ui.UI ui)
	Object object = ui.getSession().getAttribute(TEMPORARY_VARIABLE);
	ui.getSession().setAttribute(TEMPORARY_VARIABLE, null);
	return object;


And if I want to pass a simple type (String, long…) to view I am going to use what you have suggested me.

How do you handle TabBarView?

How do you mean?

I used the following between View to pass parameter:

public void enter(ViewChangeListener.ViewChangeEvent event) {

Navigator navigator = ui.getNavigator();
navigator.navigateTo(InfoView.VIEW_NAME + “/” + personen.get(index).getId());

In TabBarView I now used:

public void enter(ViewChangeListener.ViewChangeEvent event) {
    if(event.getParameters() != null) {
        String id = event.getParameters();
        addTab(new MainView(id), "Main");  <------
        addTab(new GroupView(), "Group");
        addTab(new NoteView(), "Note");
        addTab(new ExtraView(), "Extra");

Is there a better way? I.e. how to I pass in state from a View to a TabBarView to it’s Views?
Im now thinking to start using an EventBus, which one is best for Vaadin?

That is one way of doing it, yes. Of course, an EventBus is another. For Vaadin I would recommend e.g. the BlackBoard add-on.

In regards to ‘a better way’, that really depends on the rest of your app. The way you have there (passing parameters in the constructor) is probably the most widely used and simplest way of doing things. If it is enough in your case, I’d stay with that.

With the Navigator registered in the UI I can navigate and send parameters. After visiting a couple View’s, I need to show
a final TabBarView. Also showed above, where I pass in my id, after I passed the id along into the different TabBarView
View constructors. Is there a better way to do this? Now it seems I have to destroy all the tabs next time around and then
again pass it in via the constructor…

as I can send a file in grails to generate a pdf file … I want you to send automatic ???

I need help please

Again, without seeing how your code is structured I am reluctant to give any definitive answers. You don’t need to re-create the tabs if you can just change the content in them:

addTab(main= new MainTab(id));
//and then later..

Pabel, I didn’t quite understand your question. However, there are no built in helpers to generate PDFs in Vaadin.

If you want more information about the topic, please create your own thread.

and sent it with a plugin I found … but thank you so Thomas Mattsson

now the problem is that when I send it to get to the destination data arrives distorted or not seen.

without enbargo when I keep it on PC if it is with all data

I report what genre with ireport

Pabel, I guess you are using a translator to ask your questions. Unfortunately it isn’t working, because I have no idea what you are asking.

Please create a new thread; we have several forum sections for non-english speakers where you might have better luck.

Thomas Mattsson i understand what you are saying is that Google is not very good translator but it is the least that could be done by the echo of that don’t speak english … my problem is that he sent a pdf file by email with a plugin of vaadin and everything is sent perfect … the bad news is that when it revised the email that came to me the data in the file are not … let me see if I can help with this problem

@Pabel Lopez Don’t post here about PDF. You have to start a new question. Your question is not relevant here. READ the guidelines!