ValueListProvider backed by Value list Document

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

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<>();
    }
}

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

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

Hi @Davey_Chu,

Did you have to do anything special to get access to the RequestContextProvider.get()? When I try to use your low level solution I get the error below.

java.lang.IllegalStateException: No content bean annotation class resource path found.
[INFO] [talledLocalContainer] at org.hippoecm.hst.content.tool.DefaultContentBeansTool.getAnnotatedClasses(DefaultContentBeansTool.java:122)
[INFO] [talledLocalContainer] at org.hippoecm.hst.content.tool.DefaultContentBeansTool.getObjectConverter(DefaultContentBeansTool.java:84)
[INFO] [talledLocalContainer] at org.hippoecm.hst.site.request.HstRequestContextImpl.getObjectConverter(HstRequestContextImpl.java:926)
[INFO] [talledLocalContainer] at org.hippoecm.hst.site.request.HstRequestContextImpl.createQueryManager(HstRequestContextImpl.java:922)
[INFO] [talledLocalContainer] at org.hippoecm.hst.site.request.HstRequestContextImpl.getQueryManager(HstRequestContextImpl.java:860)
[INFO] [talledLocalContainer] at org.hippoecm.hst.site.request.HstRequestContextImpl.getQueryManager(HstRequestContextImpl.java:846)
[INFO] [talledLocalContainer] at com.staplesconnect.cms.components.ArticleCategoryValueListProvider.(ArticleCategoryValueListProvider.java:34)
[INFO] [talledLocalContainer] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

Note that you need to setup a few things in the cms webapp to get hold of a valuelist object as bean:
in your web.xml

  <context-param>
    <param-name>hst-beans-annotated-classes</param-name>
    <param-value>classpath*:org/onehippo/forge/selection/hst/contentbean/*.class</param-value>
  </context-param>

Add this to your cms-dependencies.xml

    <dependency>
      <groupId>org.onehippo.cms7</groupId>
      <artifactId>hippo-plugin-selections-hst-client</artifactId>
    </dependency>

And try again