ValueListProvider backed by Value list Document


#1

Hi community,

I have a @ParametersInfo class that uses a @DropDownList valueListProvider with hard-coded values returned by getValueList(). Is it possible to get these values from, for example, a Value list Document instead? I tried to use SelectionUtil:getValueListByIdentifier, but RequestContextProvider.get().getSiteContentBaseBean() returns null (when trying to edit a catalog item from the Channel Manager)

Kind regards,
Davey


#2

I got it working using the following code, but I’m hoping there’s a less ‘low level’ way:

public class MyValueListProvider extends GenericValueListProvider {

    @Override
    public Map<String, String> getValueList() {
        try {
            HstRequestContext context = RequestContextProvider.get();
            Node rootNode = context.getSession().getRootNode();
            Node valueListNode = JcrUtils.getNodeIfExists(rootNode, "content/documents/administration/valuelists/myvaluelist");
            HstQueryResult result = context.getQueryManager().createQuery(valueListNode, ValueList.class).execute();
            ValueList valueList = (ValueList) result.getHippoBeans().nextHippoBean();
            return SelectionUtil.valueListAsMap(valueList);
        } catch (Exception e) {
            log.error("Error resolving valuelist", e);
        }

        return new HashMap<>();
    }
}

#3

Not sure about your use case but did you see the Spring instantiated ValueListManager to make ValueLists available in the delivery tier?
See https://documentation.bloomreach.com/library/concepts/plugins/selections/delivery-tier.html

HTH
Jeroen


#4

Hi Jeroen,

Thank you for your reply. The ValueListManager you mention is what I initially tried (indirectly through SelectionUtil). Should it be possible to getSiteContentBaseBean() when editing a catalog item from the Channel Manager? Any idea why it would return null for me?

Kind regards,
Davey