Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VAADIN client component logic

I use VAADIN framework in my simple application. I have my 2 custom components e.g.

@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 bind them on server side.

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

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

Question is that I don't know how to send bind infomation to VComponent1.

VComponent1 should have 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 server part of Component2 because of some specific time issues. VComponent1 should have direct access to VComponent2.

Could you please help me with my scenario.

Thanks, Aritomo

like image 849
aritomo Avatar asked May 23 '26 20:05

aritomo


1 Answers

You can communicate a reference to another Vaadin component like this:

Server-side:

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

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

Client-side:

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

    Paintable componentPaintable = uidl.getPaintableAttribute("mycomponent", client);
    ..
}
like image 84
Henri Kerola Avatar answered May 26 '26 23:05

Henri Kerola