Small Help I am missing something

Guys.

I want to call a window from menuBar. The exemples on vaadin showcase calls a notification.

I want something like this:

private Command menuCommandClient = new Command() {
    @Override
    public void menuSelected(MenuItem selectedItem) {
        new ClientView();
    }
};

Then I will create a class named ClientView() but it’s not working…

see the ClientView() class

public class ClientView extends Window{

public ClientView() {   
    super("Client Registration");
    addComponent(this);
}

}

I am new at Vaadin yet. Sorry if this is too easy.

Thank You

2 issues that I can see; you shouldn’t call addComponent() with a Window, call addWindow instead. The second one is that in the Window constructor, you are trying to add the Window to the Window itself, which doesn’t work. so, instead of

new ClientView();

you should do

getWindow().addWindow(new ClientView()); for Vaadin 6 and getUI().addWindow(new ClientView()); in Vaadin7 and remove the addComponent()-call.

Hi Thomas,

Thank you so much for the help.

When I do getWindow().addWindow(new ClientesView()); my IDE complains about “Method getWindow() in class application cannot be applied to given types.”

Do you know what I am missing ? IT’s just a test that I am doing. Here is the whole code:

package com.example.vaadin;

import com.vaadin.Application;
import com.vaadin.ui.;
import com.vaadin.data.
;
import com.vaadin.ui.MenuBar.Command;
import com.vaadin.ui.MenuBar.MenuItem;

public class MyApplication extends Application {

@Override
public void init() {

    Window mainWindow = new Window("MyApplication");

    VerticalLayout vl = new VerticalLayout();
    vl.setImmediate(false);
    vl.setSizeFull();
    vl.setWidth("860px");
    vl.setHeight("120px");
    vl.setMargin(true);


    MenuBar mb = new MenuBar();
    mb.setImmediate(false);
    mb.setWidth("-1px");
    mb.setHeight("-1px");
    vl.addComponent(mb);
    MenuBar.MenuItem Cadastro = mb.addItem("Cadastro", null);
    Cadastro.addItem("Clientes", menuCommandClient);

    MenuBar.MenuItem Seguranca = mb.addItem("Segurança", null);
    Seguranca.addItem("Usuários", null);


    mainWindow.addComponent(vl);
    setMainWindow(mainWindow);
}

private Command menuCommandClient = new Command() {
    @Override
    public void menuSelected(MenuItem selectedItem) {
        getWindow().addWindow(new ClientesView());
    }
};

}

In that case I mis-remembered the API; you need a Application.getMainWindow() call in there as well.

getMainWindow() worked !!! :slight_smile:

Thank You Very much