2012-04-11 56 views
3

我在我的簡單應用程序中使用了VAADIN框架。 我有我的2個自定義組件,例如VAADIN客戶端組件邏輯

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

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

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

我想將它們綁定在服務器端。

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

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

問題是我不知道如何發送綁定信息到VComponent1。

VComponent1應該有直接的聯繫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); 
    } 
} 

我需要避免由於某些特定的時間問題通過COMPONENT2的服務器部分的通信。 VComponent1應該可以直接訪問VComponent2。

你能幫我解決我的情況嗎?

感謝, 縣有朋

回答

2

您可以參考傳達給另一個Vaadin組件是這樣的:

服務器端:

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

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

客戶端:

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

    Paintable componentPaintable = uidl.getPaintableAttribute("mycomponent", client); 
    .. 
} 
相關問題