close

Filter

loading table of contents...

Content Application Developer Manual / Version 2201

Table Of Contents

4.3.3.2 View Lookup

Looking up a view for a given bean is performed by a service called ViewDispatcher. It computes the bean's type hierarchy by taking its super types, interfaces, and even HasCustomType implementations into account. Then it asks the underlying view repositories to provide a template (or view, respectively) by passing the bean's type. If a view repository cannot provide such a view, then it will be asked iteratively for the bean's super type until a matching view can be provided.

Example:

Assume a class com.company.Base that is extended by com.company.Article. If during a view lookup for a bean of type com.company.Article there is no template com.company/Article.jsp available, but a template com.company/Base.jsp can be found, then the latter template is used.

The view dispatcher is invoked whenever a bean is rendered. This happens at least once per request. When a controller has returned with a ModelAndView instance, then the bean self is extracted and used to find the root view for the request. While executing a template, it might happen that a child bean is rendered by another template. When passing this bean to <cm:include> another view lookup and rendering is triggered.

View lookup sequence

Figure 4.7. View lookup sequence


Caution

Caution

Although it is possible for the CAE to look up all types, it is encouraged to write templates for interfaces only. While View lookups are cached, it may not always be desirable to cache lookups indefinitely, also caches are not filled every time a CAE is started. Going through the hierarchy of all types for every view lookup can be very costly, and a production CAE easily reaches a 6-digit number of View lookups (100.000+) until all views are cached.

To limit CAE lookups to certain types, set the Spring property cae.view.filter-lookup-by-predicate to true. Types ending on "Impl", "Base" and a few technical types will be removed from the type hierarchy before doing the View lookup. This reduces the number of lookups dramatically (up to 80%).

If you cannot adhere to the CoreMedia naming conventions and need a view lookup, for example for a class that ends on "Impl", you can add exceptions to this rule to the viewlookupPredicate property includes.

This is an example on how to add class names that should be included in the View lookup in addition to all interfaces.

<customize:append id="addMyViewlookupIncludes" bean="viewlookupPredicate" property="includes"
                  enabled="${cae.view.filter-lookup-by-predicate:true}">
  <description>
    Overrule the predicate's exclusion patterns for these classes.
  </description>
  <list>
    <value>my.package.MyViewRelevantBeanImpl</value>
  </list>
</customize:append>

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.