close

Filter

loading table of contents...

Content Application Developer Manual / Version 2204

Table Of Contents

4.3.3.1 View Repository

The CAE uses a concept called ViewRepository to organize its views. A ViewRepository can be understood as a store that contains JSP or FreeMarker templates for beans of certain types.

Template Views

The default implementation ResourceViewRepository looks up templates for a given type at a location <package>/<class>.<fileextension> below a configured base location such as /WEB-INF/templates. For instance, a JSP template for a bean of type com.company.Article is looked up at a location /WEB-INF/templates/com.company/Article.jsp. A template for the same bean but with a specific view name asTeaser is looked up at location /WEB-INF/templates/com.company/Article.asTeaser.jsp.

Caution

Caution

Note that the type's package name isn't mapped to a template location containing nested directories (like com/company/) but to a single directory (like com.company/).

The file extension must match a supported view engine, that is, .jsp for a JSP template or .ftl for a FreeMarker template.

Programmed Views

Besides templates, a resource view repository might also contain so called "programmed views". These are view instances implemented in Java rather than in a template language. To write a programmed view, implement ServletView or TextView. If a programmed view is added to the predefined Map "programmedViews", it will be used for rendering.

For example, this is a simplified version of a programmed view implementation that renders com.coremedia.xml.Markup as plain text:

/**
 * Programmed view that renders a given Markup as plain text
 */
public class PlainView implements TextView {

  @Override
  public void render(Object bean, String view, Writer writer, HttpServletRequest request, HttpServletResponse response) {

    Markup markup = (Markup) bean;
    // create serializer instance for scripts
    PlainTextSerializer handler = new PlainTextSerializer(writer);

    // transform and flush markup
    markup.writeOn(handler);
  }
}

This is how a programmed view is added to view repositories with a customizer:

<!-- programmed view to render plain markup -->
<bean id="plainView" class="com.company.PlainView"/>

<!-- add programmed views to predefined map "programmedViews" -->
<customize:append id="customProgrammedViews" bean="programmedViews">
  <map>
    <entry key="com.coremedia.xml.Markup#plain" value-ref="plainView"/>
  </map>
</customize:append>

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

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