Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
book-of-vaadin.pdf
Скачиваний:
88
Добавлен:
24.03.2015
Размер:
13.43 Mб
Скачать

Vaadin JPAContainer

Refreshing JPAContainer

In cases where you change JPAContainer items outside the container, for example by through an EntityManager, or when they change in the database, you need to refresh the container.

The EntityContainer interface implemented by JPAContainer provides two methods to refresh a container. The refresh() discards all container caches and buffers and refreshes all loaded items in the container. All changes made to items provided by the container are discarded. The refreshItem() refreshes a single item.

21.4.3. Nested Properties

If you have a one-to-one or many-to-one relationship, you can define the properties of the referenced entity as nested in a JPAContainer. This way, you can access the properties directly through the container of the first entity type as if they were its properties. The interface is the same as with BeanContainer described in Section 9.5.4, “BeanContainer”. You just need to add each nested property with addNestedContainerProperty() using dot-separated path to the property.

//Have a persistent container JPAContainer<Person> persons =

JPAContainerFactory.make(Person.class, "book-examples");

//Add a nested property to a many-to-one property persons.addNestedContainerProperty("country.name");

//Show the persons in a table, except the "country" column,

//which is an object - show the nested property instead

Table personTable = new Table("The Persistent People", persons); personTable.setVisibleColumns(new String[]{"name","age",

"country.name"});

// Have a nicer caption for the country.name column personTable.setColumnHeader("country.name", "Nationality");

The result is shown in Figure 21.5, “Nested Properties”. Notice that the country property in the container remains after adding the nested property, so we had to make that column invisible. Alternatively, we could have redefined the toString() method in the country object to show the name instead of an object reference.

Figure 21.5. Nested Properties

You can use the * wildcard to add all properties in a nested item, for example, "country.*".

464

Nested Properties

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]