New CustomComponent

Hi all,

I am trying out Vaadin, and feel very happy until now with it, but have a question on how should I best approach the following interface need.
Any thoughts are very welcome and thanks in advance for reading.

In a page I need to select entity instances and display the selected ones by means of a Label, which Caption value must be a toString() from each of those beans.
At start, the label must display “(No data selected)”, when CLICKING on it I must open a subwindow and select the instances I am interested in, and when closing de subwindow, the selected items must be reflected in the Label caption.

After that, when saving the page where this “selectlabel” is, the data must be attached to the entity being edited in that page.

Hope it was clear.

I have to use this funcitonality overall in my application so it is pretty important for me to solve this in a vaadin way, that is being able to write an ArrayList backed Property, out of the getValue() method of the Label. But Label is not a Field.
I tried using a button, but then I realized that getValue() method for buttons must be boolean.
You may say, why not use a Select?, because I need to search the selectable values according to several criteria.

When I used JSF, there was a “selectInputText” component where the programmer could smoothly define these things, but in Vaadin haven’t found an analogue component. Therefore I partially solve it by showing a subwindow to enhance search criteria.

I think I should use a CustomComponent by extending button component. Or extend Label enabling click events but do not know how possible is that.
Anyway if there was an easy solution I would like to spare that effort. Or does it already exist a component like that somewhere?

What are your thoughts?

Many , many thanks for your attention.

Chal-lo.

Use a CustomField (
add-on for Vaadin 6
, directly included in Vaadin 7). It implements the (large) Field interface and otherwise works like a CustomComponent, you only need to write a few methods yourself.

For click events, if you don’t want to extend the client side, you can wrap the Label e.g. in a CssLayout and use a LayoutClickListener on it.

this is fantastic!. So simple!
Build quickly a Label inside a VerticalLayout and set it as CompositionRoot.

Thank you very much Henri. You saved me a lot of time…

One more question, the binding to the datasource seems not to be working property.

What I do is to create a BeanItem with the entity that holds the data and set it to the created field.

As an example let’s say that :

Class A owns one instance of Class B in the field “fieldName”

so what i do is :




BeanItem bi = new BeanItem(a);
Property p = bi.getItemProperty("fieldName"); //this returns a MethodProperty of type B.
(...)
LabelSelect ls = new LabelSelect((..data I need to define the selection...), B.class);
ls.setPropertyDataSource(p);


and then inside the CustomField LabelSelect:



public B getValue(){
        return b; //I would like B to be Object instead, or a parametrized type, but compiler complains. 
 }

public Class<?> getType(){
        return B.class;
}

The whole process of selection works fine and the affected fields in the Custom field work properly. Only setting the value through the property is not working.
I don’t know in depth the inner working of Vaadin and its datamodel architechture, just grasping the surface, but from my understanding so far, this should work. I understant that Property, or through Property, the value should be “getted” from the customcomponent and written to the source object. Well, the value is getted, but not written, as I can state whle debugging.

Can you figure out why not?

Many thanks in advance.

Chal-lo.