Selection Plugin Delivery Tier Configuration and Implementation

Content Bean

Use the Beanwriter tool in the setup application to update the content bean for any document type that includes a selection field.

In the repository, a selection field is stored as a String (or Boolean) property. The corresponding getter method in the content bean is implemented the same way as for a standard String property:

@HippoEssentialsGenerated(internalName = "myproject:city") public String getCity() { return getProperty("myproject:city"); }

Expose Value Lists to the Site

When a CMS user selects an option in a selection field, the repository stores the key for that value. To display the associated label in the delivery tier, the site application must have access to the value list.

The setup application provides a user interface to make value lists available to the site application using the ValueListManager Spring bean.

valueListManager.xml

The generated Spring bean configuration is located in your project's site module at site/components/src/main/resources/META-INF/hst-assembly/overrides/valueListManager.xml:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="org.onehippo.forge.selection.hst.manager.ValueListManager" class="org.onehippo.forge.selection.hst.manager.DefaultValueListManager"> <constructor-arg> <map> <!--<entry key="name" value="/absolute/repository/path"/>--> <entry key="cities" value="/content/documents/administration/value-lists/cities"/> </map> </constructor-arg> </bean> </beans>

Accessing Value Lists

You can access the ValueListManager bean from any page component class. The following example extends the standard Content Component and overrides the doBeforeRender method to retrieve the cities value list and add it to the request attributes:

public class NewsComponent extends EssentialsContentComponent { @Override public void doBeforeRender(HstRequest request, HstResponse response) { super.doBeforeRender(request, response); final ValueList citiesValueList = SelectionUtil.getValueListByIdentifier("cities", RequestContextProvider.get()); if (citiesValueList != null) { request.setAttribute("citiesMap", SelectionUtil.valueListAsMap(citiesValueList)); } } }

Template Usage

In your template, use the value list to look up the label for the key stored in the document:

${citiesMap[document.city]}
Share Feedback
Page: /build/plugins/selections/delivery-tier
Section: Build
Category *