Movatterモバイル変換


[0]ホーム

URL:


BloomreachBloomreach
Hippo CMS

Bloomreach Documentation version

Bloomreach.com

Creating Content Beans

Introduction

To make customdocument types available in a site, the backing JCR nodes must be wrapped in aHippoBean object. A Content Bean is a light-weight wrapper around such a node and a simplePOJO. For a request, you can access the Content Bean mapped to the requested page via

HstRequestContext ctx = RequestContextProvider.get();ctx.getContentBean()

SeeHstRequestContext documentation for more information.

For a typical document type created using theDocument Type Editor, the corresponding content bean class isdynamically generated at runtime by default (as of version 13.2.0) or can optionally be generated using theBeanwriter tool in theEssentials setup application. However, in some cases it might be necessary to customize the generated class, or write one from scratch.

Document Type

For the mapping to work it must be annotated withthe org.hippoecm.hst.content.beans.Node annotation. Set the mapped JCR node type with thejcrType parameter.

@Node(jcrType="myproject:textdocument")public class TextDocument extends HippoDocument{ ... }

Read the page aboutAutomatic Scanning to see how to enable the actual scanning of the Bean.

Primitive Fields

To make the properties of the JCR node available in components and templates the bean must have appropriate getters. The return type of the getter for a property depends on the type of it.

An example of a typical getter for a property is:

public String getTitle() {    return getSingleProperty("myproject:title");}

Here is a list of Primitve fields as defined in the Document Type Editor in the CMS, the matching JCR property type and the corresponding types in Java.

Primitive CMS fieldJCR property typeJava typesRemarks
BooleanBooleanboolean 
String, Text, LabelStringjava.lang.StringThe Text field offers a multi line field in the CMS.
Date, CalendarDateDatejava.util.Calendar 
Decimal NumberDoubledouble 
Integer NumberLonglong 
DocbaseStringjava.lang.StringThis CMS field provides a document picker. The JCR UUID of the choosen document is simply stored as a String.
Formatted textStringjava.lang.StringUse the formattedText attribute of the <hst:html /> tag in your template.
PasswordStringjava.lang.StringNote that this only implies a 'hidden' input in the cms. The entered value is not stored in a encrypted way.

Compound Fields

For compound types in document types the information is stored in JCR as child nodes of the documents' node. The getter in the document Bean should then return the Bean type that maps the content of the child node.

Some examples of typical getters for compound type fields are:

public HippoBean getRelatedDocument() {    return getLinkedBean("myproject:relateddocument", HippoBean.class);}
public List<HippoGalleryImageSet> getImages() {    return getLinkedBeans("myproject:images", HippoGalleryImageSet.class);}
public HippoHtml getDescription() {    return getHippoHtml("myproject:description");}

For custom compounds you must write your own beans. For the compounds provided by Hippo these are the corresponding beans.

CMS Compound fieldJCR node typeMatching Bean typeRemarks
Rich Text Editorhippostd:htmlorg.hippoecm.hst.content.beans.
standard.HippoHtml
Use the <hst:html /> tag in your template.
imagelinkhippogallerypicker:imagelinkorg.hippoecm.hst.content.beans. standard.HippoGalleryImageSetBeanUse org.hippoecm.hst.content.beans.standard.HippoItem#getLinkedBean to get the target Bean. Use #getBean to retrieve the child node of the document that contains the link information.
Resourcehippo:resourceorg.hippoecm.hst.content.beans.
standard.HippoResourceBean
Linkhippo:mirrororg.hippoecm.hst.content.beans.
standard.HippoMirror

Prevent the Beanwriter from Modifying Custom Bean Methods

Even if a project contains custom content bean classes, the Beanwriter can still be useful. For example, to generate bean classes for newly added document types, or even to generate methods for fields added to existing document types. However, care must be taken to not let the Beanwriter modify any existing methods in existing bean classes.

To prevent the Beanwriter from making any modifications to a method in a bean class:

  • Add the @HippoEssentialsGenerated annotation to the method.
  • Set the annotation's internalName parameter to the JCR property name of the field.
  • Set the annotation's allowModifications parameter tofalse.

Example:

@HippoEssentialsGenerated(internalName = "myproject:title", allowModifications = false)public String getTitle() {    return getSingleProperty("myproject:title");}

You can also prevent the whole bean class from being modified by the Beanwriter by updating the class level annotation in the same way.

Persistence

Typically content beans only have getters and consequently are "read-only". If a document type is used to store content submitted by site visitors its content bean must support persistence.

To support persistence a content bean must have setters and in addition must implement theorg.hippoecm.hst.content.beans.ContentNodeBinder interface.

Did you find this page helpful?
How could this documentation serve you better?
Cheers!
On this page
    Did you find this page helpful?
    How could this documentation serve you better?
    Cheers!

    [8]ページ先頭

    ©2009-2025 Movatter.jp