object addition to label

Hi. There is object with id and name which I’m planning to add to Label. I want display name in label and after getting value of label I want get object. How to do this?

What do you mean by “object”?

Object of class.

public class IdName
{
private Integer id;
private String name;
}

You need to add a constructor and setters/getters to your class so that you can set their variables.

public class IdName
{
private Integer id;
private String name;

public IdName(Integer id, String name){
this.id = id;
this.name = name;
}

public void setid(Integer id){
this.id = id;
}

public Integer getid(){
return id;
}

public void setname(String name){
this.name = name;
}

public String getname(){
return name;
}

}

This way you can create a new instance of IdName and set the variables or you can change the id and name of an existing instance.

That’s not what I mean. It is necessary to add instance of IdName to Label in vaadin. The name field of IdName must be displayed in Label. But after getting value of this Label I want to get whole instance of IdName.

Bonjour,
If I understand well, you should be able to do something like this :

IdName idname = new IdName(1, “Gilles”);
Label myLabel = new Label();
myLabel.setData(idname); // the instance object is attached to the label
myLabel.setValue(idname.getName()); // only the name is displayed on top of the label

You retrieve the object like this :

IdName idname2 = (IdName) myLabel.getData();

Hope it is want you are looking for.

Where are you saving your instances of IdName? If you have them in a Container you could iterate through it and then check with an if-statement if it has the right name.

I think you should look at
https://vaadin.com/forum#!/thread/3376266

Implement your own field that displays (what ever value) in the Label, but keeps the original property value.
Take note of 4th post
https://vaadin.com/forum#!/thread/3376266/3383421
by Henri Sara to save you some work…

Gilles Carpentier, that solution was helped me. Thanks to all.