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.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
SharedState in CustomWidget
Hello,
I'm currently trying to implement a CustomLayout via Widgets in Vaadin.
Therefore i created the following classes:
MyCustomLayout(Server-Class)
MyCustomLayoutWidget(Client-Class)
MyCustomLayoutConnector
MyCustomLayoutState
In this Layout I'm storing the added Component with its Constraints in a Map in the MyCustomLayoutState.
But if i try to access the Map from the State my Constraints are always null.(They aren't when they get added into the Map on the Serverside).
This is my Map in the SharedState
public Map<Connector, Constraint> childData = new HashMap<Connector, Constraint>();
And this are my Constraint and Anchor classes.
/**
* The Constraint stores the top, left, bottom and right Anchor for layouting a component.
*/
public static class Constraint implements Cloneable, Serializable
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class members
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/** The top anchor. */
private Anchor topAnchor;
/** The left anchor. */
private Anchor leftAnchor;
/** The bottom anchor. */
private Anchor bottomAnchor;
/** The right anchor. */
private Anchor rightAnchor;
Initialization, getter setters
}
/**
* The Anchor gives the possible horizontal and vertical positions.
*/
public static class Anchor implements Serializable
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class members
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/** Constant for horizontal anchors. */
public static final int HORIZONTAL = 0;
/** Constant for vertical anchors. */
public static final int VERTICAL = 1;
/** The orientation of this anchor. */
private int orientation;
/** The related anchor to this anchor. */
private Anchor relatedAnchor;
/** The second related anchor to this anchor. */
private Anchor secondRelatedAnchor;
/** The second related anchor to this anchor. */
private float relativePosition;
/** true, if this anchor should be auto sized. */
private boolean autoSize;
/** The position of this anchor. */
private int position;
/** True, if the anchor is not calculated by components preferred size. **/
private boolean relative;
/** True, if the relative anchor is not calculated. **/
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Initialization, getter setters
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
Any hints why this isnt working?
Hi,
do you get any compilation errors while compiling your widgetset? Please use "strict" compiler parameter if possible. Also, you don't mention where the Constraint and Anchor classes are located. Make sure they are accessible by the client-side also.
-tepi
Hello Teppo,
My Anchor and my Constraint class are located in the MyCustomLayoutState class so they should be accessible by both the client and the server. I just saw that i get this exception right here:
So is it not possible to have anchors in my anchor class? It's needed for my Layout to work so is there any way of making this work?
Hi again,
not sure why it won't work - I think it should. I'm wondering if a reference loop (which seems possible here) could break the serialization.
Would it be possible for you to provide the classes needed to reproduce the issue, so I could take a closer look?
-tepi
Hi Teppo im very thankful for your help.
I fixed a mistake of mine and now it comes down to the relatedAnchors always being null on the client when they are not on the server. I added the classes to the attachments. I also added the snipped of the UICode
Thx again for your help!
Greets Thomas
Hi again!
Seems you have the following code in your Anchor class:
public Anchor getRelatedAnchor() {
return null;
}
public Anchor getSecondRelatedAnchor() {
return null;
}
Changing these to return the correct values fixes the issue and the values arrive on the client side properly.
-tepi
Hi!
Oh gosh this is embarrassing. Sorry to waste your time with something trivial like this.
Thx a lot!