Table getValue Problem

Hi!

I created a table and I added 2 columns (using addContainerProperty). The first column “Name” and the second “Age”.
Then I added two TextField (tf and tf2). I want that when I select a row of my table, “tf” gets the value of “Name” and "tf2 " gets the value of “Age”.

I already read the Address Book but I didnt understand it :frowning: (i’m newbie)

here’s a screenshot:

“tf” gets all the row’s selected value.

But I need those values in each TextField separately.

Here’s my code:

Thank you vaadiners for your help! :smiley:

Table.getValue() returns an Item id which you can use to fetch the properties with. Change your ValueChangeListener to something like this and it should work:


table.addListener(new Property.ValueChangeListener() {
			public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
				Object id = table.getValue();
				Item item = table.getItem(id);
				tf.setValue(id == null ? null : item.getItemProperty("Name").getValue());
				tf2.setValue(id == null ? null : item.getItemProperty("Age").getValue());
			}
		});

Looks a lot like a regular master-detail editor case, see
an example
.

If you’re a Pro Account subscriber, see article
#255
.

plz try this code,thanks

            tf.setValue(id == null ? null : item.getItemProperty("Name").getValue());
            tf2.setValue(id == null ? null : item.getItemProperty("Age").getValue());

Avinash Nair,
for me code above was really helpful, thanks.