Search code examples
annotationshippocms

How can I set up a Dropdown List using Template Composer Annotation in Hippo CMS?


Currently working on a simple component and I need the drop down to have a display name of :

One, Three, and Five

However, I need that value to actually equal the integer value of these display names. One = (int) 1, Three = (int) 3, Five = (int) 5.

package com.authx.components;

import org.hippoecm.hst.core.parameters.DropDownList;
import org.hippoecm.hst.core.parameters.Parameter;

public interface PressEventComponentInfo {

    @Parameter(name = "number", required = true, displayName = "Release Number",       defaultValue="three")
    @DropDownList({"one", "three", "five"})
    String getNumber();
}

Solution

  • You can do this by using i18n for property values.

    For a dropdown field you can use the parameter name followed by a slash and then the parameter value again as the key (e.g. in your example, 'number/1=One').

    + site
        + src
            + main
                + java
                |   +com.authx.components.PressEventComponentInfo
                + resources
                    +com.authx.components
                        - PressEventComponentInfo.properties
    

    You can find more information about this subject and some examples on the HST Component Parameters documentation page and the channel info page.

    And adding the following properties:

    number/1=One
    number/3=Three
    number/5=Five