VAADIN Client Component Logic

I am using VAADIN in my simple application. I have 2 custom components, for example.

@ClientWidget(value = VComponent1.class)
public class Component1 {
    private Component2 cmp2;

    public void setDataSource(Component2 cmp2) {
        this.cmp2 = cmp2;
    }
}

and

@ClientWidget(value = VComponent2.class)
public class Component2 {
}

I would like to link them server side.

...
Component2 cmp2 = new Component2();
Component1 cmp1 = new Component1();
cmp1.setDataSource(cmp2);

mainWindow.addComponent(cmp1);
mainWindow.addComponent(cmp2);
...

The question is, I don’t know how to send link information to VComponent1.

VComponent1 must have a direct link to VComponent2

public class VComponent2 implements Paintable {

    public String getCurrentData() {
        return "Hello";
    }
}


public class VComponent1 implements Paintable,
ClickHandler {
    VComponent2 dataSource;

    @Override
    public void onClick(ClickEvent event) {
        super.onClick(event);
        String data = dataSource.getCurrentData();
        client.updateVariable(uidlId, "curData", data, true);
    }
}

I need to avoid communication through the server side of Component2 due to some specific time issues. VComponent1 must have direct access to VComponent2.

Could you help me in my script.

Thanks Aritomo

+3
source share
1 answer

You can pass the link to another Vaadin component as follows:

server side:

public void paintContent(PaintTarget target) throws PaintException {    
    ..

    target.addAttribute("mycomponent", component);
    ..
}

on the client side:

public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    ..

    Paintable componentPaintable = uidl.getPaintableAttribute("mycomponent", client);
    ..
}
+2
source

All Articles