Yoiku
Yoiku

Reputation: 912

How do I get a certain value from a row in vaadin?

This is the problem, I have a vaadin table that represent people information (for example) and when someone clicks on a row I want to extract the cellphone number.

Here is part of the code of the listener:

table_2.addListener(new ItemClickEvent.ItemClickListener() {

        @Override
        public void itemClick(ItemClickEvent event) { // TODOAuto-generated // method stub
            String resultado = (table_2.getItem((Object)event.getItemId()))
                    + "";
            resultado = resultado.substring(resultado.indexOf("phone"),
                    resultado.indexOf("|weight"));
            label_3.setValue(resultado);
        }
    });

It worked one time but now it doesn't. The code returns a Null, so when I try to parse the object to string it crash.

Upvotes: 3

Views: 6584

Answers (1)

nexus
nexus

Reputation: 2937

Try the following:

table.addListener(new ItemClickListener() {

    @Override
    public void itemClick(ItemClickEvent event) {

        Property itemProperty = event.getItem().getItemProperty("cellphone");
        itemProperty.getValue(); // TODO: Do something with this value.

    }
});

Upvotes: 11

Related Questions