content-management-systemhippocms

Link back query not working for ContentBlocksFieldPlugin


I am new to hippo cms so apologies if i am not using correct terminologies.

I have followed this link and got the first query working cms hippo docs

I have got 2 doctypes Master and Servant respectively.

Master doctype java and yaml file are as follows

@HippoEssentialsGenerated(internalName = "website:link")
public List<HippoBean> getLink() {
    return getLinkedBeans("website:link", HippoBean.class);
}

yaml code

  /link:
    /cluster.options:
      base.path: /content/documents
      jcr:primaryType: frontend:pluginconfig
      last.visited.enabled: true
      nodetypes:
      - website:servant
    caption: Link
    field: link
    hint: ''
    jcr:primaryType: frontend:plugin
    plugin.class: org.hippoecm.frontend.editor.plugins.field.NodeFieldPlugin
    wicket.id: ${cluster.id}.field

  /link:
    hipposysedit:mandatory: false
    hipposysedit:multiple: true
    hipposysedit:ordered: false
    hipposysedit:path: website:link
    hipposysedit:primary: false
    hipposysedit:type: hippo:mirror
    hipposysedit:validators:
    - optional
    jcr:primaryType: hipposysedit:field

Master has got linkedbean to link to servant doctype as shown above.

Now in the Servant doctype i would like to show the master details, so i added a query as shown below and it works as expected.


public Master getParentDetails() {
    final HstRequestContext context = RequestContextProvider.get();

    try {
        HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(
            this.getCanonicalBean(), context.getSiteContentBaseBean(),
            "*/website:link/@hippo:docbase",
            Master.class, false);
        linkedBeanQuery.setLimit(1);
        return (Master) linkedBeanQuery.execute().getHippoBeans().nextHippoBean();
    } catch (QueryException queryException) {
        log.warn("QueryException ", queryException);
    }
    return null;
}

The problem is when i change the plugin class in Master to plugin.class: org.onehippo.forge.contentblocks.ContentBlocksFieldPlugin and add compound list compoundList: website:junior things stop working and give error.

Note that now the getlink() method and the link yaml code shown above is moved into a new compound called junior.

Master is just for allowing multiple compounds of junior with appropriate code as shown below.


@HippoEssentialsGenerated(internalName = "website:servantlink");
public List<HippoBean> getServantlink() {
    return getLinkedBeans("website:servantlink", HippoBean.class);
}

yaml code


  /servantlink:
    /cluster.options:
      jcr:primaryType: frontend:pluginconfig
      nodetypes:
      - website:servant
    caption: groups
    compoundList: website:junior
    contentPickerType: links
    field: servantlink
    hint: ''
    jcr:primaryType: frontend:plugin
    plugin.class: org.onehippo.forge.contentblocks.ContentBlocksFieldPlugin
    wicket.id: ${cluster.id}.field
    wicket.skin: skin/content-blocks.css
  /servantlink:
    hipposysedit:mandatory: false
    hipposysedit:multiple: true
    hipposysedit:ordered: false
    hipposysedit:path: website:servantlink
    hipposysedit:type: hippo:compound
    hipposysedit:validators:
    - contentblocks-validator
    jcr:primaryType: hipposysedit:fiel

So my question is how the query should be now?

Any help would be highly appreciated. Thanks in advance


Solution

  • So finally got it working

    The master java class should be as follows. Please note use getChildBeansByName instead of getLinkedBeans here.

    @HippoEssentialsGenerated(internalName = "website:servantlink");
    public List<HippoBean> getServantlink() {
        return getChildBeansByName("website:servantlink");
    }
    

    No changes in the master.yaml its all good. Now the query part in Servant java class should be as follows.

        final HstRequestContext context = RequestContextProvider.get();
    
        try {
            HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(
                this.getCanonicalBean(), context.getSiteContentBaseBean(),
                "website:servantlink/website:link/@hippo:docbase",
                Master.class, false);
            linkedBeanQuery.setLimit(1);
            return (Master) linkedBeanQuery.execute().getHippoBeans().nextHippoBean();
        } catch (QueryException queryException) {
            log.warn("QueryException ", queryException);
        }
        return null;
    }
    

    The most important part is this website:servantlink/website:link/@hippo:docbase.