Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

resizeble panel

ahmed taha
1 decade ago Mar 24, 2011 12:04pm
Jouni Koivuviita
1 decade ago Mar 25, 2011 7:32am
ahmed taha
1 decade ago Mar 26, 2011 7:53am
Jouni Koivuviita
1 decade ago Mar 27, 2011 5:03pm
ahmed taha
1 decade ago Mar 30, 2011 10:03am
Jouni Koivuviita
1 decade ago Mar 31, 2011 5:35am

You've misunderstood the communication mechanism a bit :) but that's ok, I'll try and correct.

If you need to build your component as a composition of other components, you can do two things:

1. Build the composition in the server, i.e. extend a core layout (like VerticalLayout) just in the server and add the components normally there (layout.addComponent(button) etc.). You don't need to touch the paintContent method, that's just internal Vaadin stuff you rarely want to touch (it handles the component serialization that is sent to the client).

2. Extend a core layout in both the server and the client. In the server, add any necessary components that you need (like in the above case). In the client, add extra functionality that you need by overriding any methods you wish or adding new listeners etc.

The way you've tried to do it (add components as attributes to the serialization object inside paintContent) is a bit wrong. When you use the addAttribute(String, Component) method, you only add the id of the component to the UIDL, not the whole component rendering.

If you really wish to create this sort of component, that contains other components, you need to do something like this:

public class MyComponent extends AbstractComponent {

private Layout layout;

public MyComponent() {
     layout = new VerticalLayout();
     Label label = new Label("I am a vaadin");
     layout.addComponent(label);
}

public void paintContent(PaintTarget target) throws PaintException {
      super.paintContent(target);
      [b]layout.paint(target);[/b] // Ask the component to paint itself to the same UIDL target, creating a new "child" for this MyComponent
}

}
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    if (client.updateComponent(this, uidl, true)) {
        return;
    }
    this.client = client;
    paintableId = uidl.getId();
    root.add(new Label("gwt label"));

    [b]UIDL childUIDL = uidl.getChildUIDL(uidlPos);[/b] // Get the layout components uidl 
    [b]Paintable widget = client.getPaintable(childUIDL);[/b] // Create a new Vaadin Paintable from the UIDL
    root.add(widget);
    [b]widget.updateFromUIDL(childUIDL);[/b] // Needs to be called after the component is attached to the document
}

I hope this somehow clarifies the mechanism :)

Deleted User
1 decade ago Mar 31, 2011 8:26am
ahmed taha
1 decade ago Apr 04, 2011 7:54am
ahmed taha
1 decade ago Apr 04, 2011 7:58am
Ranjit reddy
7 years ago Jul 09, 2015 12:26pm