Content Application Developer Manual / Version 2406.0
Table Of ContentsThis section illustrates the process of defining a data view configuration. For this example, a simple site with three pages is used. The first page consists of a brief overview of two articles that are completely shown on two separate pages. These article instances are shared between the overview page and the detail pages:
The entities are represented as beans and properties where the properties are assumed to have different costs: Some are expensive to compute while others are cheap.
Bean | Property | Description | Expensive |
---|---|---|---|
PageBean
|
Title
| The page's title. | No |
Content
|
The page content as a linked
OverviewBean
or ArticleBean .
| No | |
Navigation
|
All
PageBeans
to be rendered as navigation.
| Yes | |
ContentBean
|
Page
|
The
PageBean
which embeds this bean.
| Yes |
OverviewBean
|
Teasers
|
A list of
ArticleBeans
to be rendered as teasers.
| No |
ArticleBean
|
Headline
| The article's headline. | No |
Text
| The article's text. | Yes | |
Abstract
|
The article's abstract which is extracted from property
Text
automatically.
| Yes* | |
Image
| An optional link to an image. | No | |
ImageBean
|
MimeType
| The image data's mime type. | Yes |
Data
| The binary data. | No |
Table 4.3. Bean Properties in the DataView Example. (*) The computation of property "abstract" is not expensive by itself but the access of property "text" only.
The Freemarker templates for rendering the beans are modeled as follows:
PageBean.ftl
<#-- @ftlvariable name="self" type="com.mycompany.PageBean" --> <html> <head> <title>${self.title}</title> </head> <body> <div class="content"><@cm.include self=self.content/> </div> <div class="navigation"> <ul> <#list self.navigation![] as page> <li><a href="${cm.getLink(page)}">${page.title!""}</a></li> </#list> </ul> </div> </body> </html>
ArticleBean.ftl
<#-- @ftlvariable name="self" type="com.mycompany.ArticleBean" --> <h1>${self.headline!""}</h1> <div>${self.text!""}</div> <#if self.image?has_content> <#assign imageUrl= cm.getLink(self.image)/> <img src="${imageUrl!""}" alt="image"/> </#if>
OverviewBean.ftl
<#-- @ftlvariable name="self" type="com.mycompany.OverviewBean" --> <#list self.teasers as article> <h2>${article.headline!""}</h2> <p> ${article.abstract!""} [<a href="${cm.getLink(article.page)}">more</a>] </p> </#list>
Considering the above mentioned settings, the following
dataviews.xml
file
can be derived:
<?xml version="1.0"?> <dataviews xmlns= "http://www.coremedia.com/2004/objectserver/dataviewfactory"> <dataview appliesTo="com.mycompany.PageBean"> <property name="content" associationType="dynamic"/> <property name="navigation" associationType="static"/> </dataview> <dataview appliesTo="com.mycompany.ArticleBean"> <property name="page" associationType="static"/> <property name="text"/> </dataview> <dataview appliesTo="com.mycompany.OverviewBean"> <property name="teasers" associationType="dynamic"/> </dataview> <dataview appliesTo="com.mycompany.ImageBean"> <property name="mimeType"/> </dataview> </dataviews>
All expensive associations (PageBean#Navigation
and
ArticleBean#Page
) are declared to be data viewed using the default
association type "static". Please note, that
OverviewBean#Page
is not marked
here since this is not accessed by the templates.
PageBean#Content
and
OverviewBean#Teasers
are marked with the association type "dynamic" although
they are not expensive: Instead they are used making
ArticleBean
recursively
reachable from the PageBean
. Finally, the non-associating but expensive
properties
ArticleBean#Text
and
ImageBean#MimeType
are marked
for caching as well.
ArticleBean#Abstract
is not marked here because it
benefits from the already cached ArticleBean#Text
.
Keep in mind that a perfect data view configuration depends on a lot of circumstances.
Let's say that the underlying contents are updated very rarely on the one hand but
accessed very often on the other hand. In order to reduce the number of cache read
operations, some property associations might be switched to "composition". An
additional "teaser" data view might be introduced in order to cache the ArticleBean
's
different views (overview and detail) with separate objects.
<dataviews xmlns= "http://www.coremedia.com/2004/objectserver/dataviewfactory"> <dataview appliesTo= "com.coremedia.objectserver.dataviews.examples.PageBean"> <property name="content" associationType="composition"/> <property name="navigation" associationType="static"/> </dataview> <dataview appliesTo= "com.coremedia.objectserver.dataviews.examples.ArticleBean"> <property name="text"/> </dataview> <dataview appliesTo= "com.coremedia.objectserver.dataviews.examples.ArticleBean" name="teaser"> <property name="abstract"/> <property name="page" associationType="static"/> </dataview> <dataview appliesTo= "com.coremedia.objectserver.dataviews.examples.OverviewBean"> <property name="teasers" associationType="composition" dataview="teaser"/> </dataview> <dataview appliesTo= "com.coremedia.objectserver.dataviews.examples.ImageBean"> <property name="mimeType"/> </dataview> </dataviews>