In many cases, when you display a facet value on a page, it is desirable to reformat the value, because the format used to store the values in the index is not optimized for display purposes. For example:

To reformat these values for displaying on pages, the ATG platform includes a servlet bean, atg.repository.search.refinement.RefinementValueDroplet. This servlet bean takes as input a facet selection value and the repository ID of the refinementElement that represents the facet, and outputs the value in a more human-readable form.

ATG Commerce includes a component of this class, which you can use in your pages like this:

<dsp:droplet name="/atg/commerce/search/refinement/RefinementValueDroplet">
  <dsp:param name="refinementId" value="${facetHolder.facet.id}"/>
  <dsp:param name="refinementValue" value="${facetValueNode.facetValue.value}"/>
  <dsp:oparam name="output">
    <dsp:valueof param="displayValue"/>
  </dsp:oparam>
</dsp:droplet>

To perform the formatting, RefinementValueDroplet uses a class that implements the atg.repository.search.MetaPropertyValueFormatter interface. By default, this class is atg.repository.search.DefaultMetaPropertyValueFormatter. The RefinementValueDroplet component has a defaultValueFormatter property that points to a component of this class, /atg/commerce/search/refinement/DefaultMetaPropertyValueFormatter.

DefaultMetaPropertyValueFormatter can reformat a variety of data types:

You can write a custom implementation of the MetaPropertyValueFormatter interface to use for specific faceting properties. ATG Commerce includes one such class, atg.commerce.search.PriceMetaPropertyValueFormatter, for formatting price data. It also includes a component of this class, /atg/commerce/search/PriceMetaPropertyValueFormatter.

To specify a custom formatter for a property, you create a component of your class and then register the component with the /atg/search/repository/MetaPropertyValueFormatterRegistry component. MetaPropertyValueFormatterRegistry has a valueFormatterMap property which maps property names to their associated formatter components. For example, to specify that the PriceMetaPropertyValueFormatter should be applied to the price property, ATG Commerce adds this configuration:

valueFormatterMap+=\
   price=/atg/commerce/search/PriceMetaPropertyValueFormatter

When it formats a value, RefinementValueDroplet first checks the MetaPropertyValueFormatterRegistry to see if there is a custom MetaPropertyValueFormatter registered for the property name, and if there is, uses that formatter. If there no custom formatter registered for the property, it uses the DefaultMetaPropertyValueFormatter.

For more information about RefinementValueDroplet, see Appendix A, Commerce Search Servlet Beans.

 
loading table of contents...