简体   繁体   English

如何用动态值填写Hippo CMS中的Dynamic Dropdown?

[英]How to fill out Dynamic Dropdown in Hippo CMS with dynamic values?

I have document type which contains "Dynamic Dropdown" field, and I want to fill it with some dynamic data. 我的文档类型包含“动态下拉列表”字段,我想用一些动态数据填充它。 I couldn't figure out how to do it (couldn't find any adequate information, documentation, example about this). 我不知道该怎么做(找不到任何足够的信息,文档,关于此的示例)。 From links that I found I was able to do following things: 通过我发现的链接,我可以执行以下操作:

1) I've created service called SitemapValueListProvider in /hippo:configuration/hippo:frontend/cms/cms-services , with following properties: 1)我在/ hippo:configuration / hippo:frontend / cms / cms-services中创建了名为SitemapValueListProvider 的服务 ,具有以下属性:
plugin.class = com.test.cms.components.SitemapService plugin.class = com.test.cms.components.SitemapService
valuelist.provider = service.valuelist.custom valuelist.provider = service.valuelist.custom

2) In CMS project created class com.test.cms.components.SitemapService 2)在CMS项目中创建类com.test.cms.components.SitemapService

public class SitemapService extends Plugin implements IValueListProvider {

  private final static String CONFIG_SOURCE = "source";

  public SitemapService(IPluginContext context, IPluginConfig config) {
    super(context, config);

    String name = config.getString(IValueListProvider.SERVICE, "service.valuelist.custom");
    context.registerService(this, name);
  }

  @Override
  public ValueList getValueList(String name, Locale locale) {
    ValueList valuelist = new ValueList();

    if ((name == null) || (name.equals(""))) {
        System.out.println("No node name (uuid or path) configured, returning empty value list");
    } else {
        valuelist.add(new ListItem("custom4", "Custom Value 4"));
        valuelist.add(new ListItem("custom5", "Custom Value 5"));
        valuelist.add(new ListItem("custom6", "Custom Value 6"));
    }

    return valuelist;
  }

  @Override
  public List<String> getValueListNames() {
    List<String> list = new ArrayList<>(1);
    list.add("values");
    return list;
  }

  @Override
  public ValueList getValueList(IPluginConfig config) {
    if (config == null) {
        throw new IllegalArgumentException("Argument 'config' may not be null");
    }
    return getValueList(config.getString(CONFIG_SOURCE));
  }

  @Override
  public ValueList getValueList(String name) {
    return getValueList(name, null/*locale*/);
  }
}

3) In CMS project created class com.test.cms.components.TestPlugin 3)在CMS项目中创建类com.test.cms.components.TestPlugin

public class TestPlugin extends Plugin{

  public TestPlugin(IPluginContext context, IPluginConfig config) {
    super(context, config);
    context.registerService(this, "service.valuelist.custom");
  }    
} 

4) For field /hippo:namespaces/cms/TestItem/editor:templates/_default_/dynamicdropdown of document type provided following properties: (using console) 4)对于字段/ hippo:namespaces / cms / TestItem / editor:templates / _default_ / dynamicdropdown ,提供以下类型的文档类型:(使用控制台)
plugin.class = com.test.cms.components.TestPlugin plugin.class = com.test.cms.components.TestPlugin

But still unable to obtain data dynamically. 但是仍然无法动态获取数据。 Nothing happens at all. 什么都没发生。
I'm using HippoCMS 10 Community Edition 我正在使用HippoCMS 10 Community Edition

you are totally on the right track and I can't spot any obvious reason why this is not working. 您完全处于正确的轨道上,我无法找到任何不正常的明显原因。 Can you double check a few things? 您能仔细检查几件事吗?

  • look for an error in the logs, possibly at the early start of the CMS. 在日志中寻找错误,可能是在CMS的早期启动。 Maybe there is an error during the bootstrap process. 引导过程中可能出现错误。
  • activate the development mode in the CMS: this adds extra logging in the CMS. 激活CMS中的开发模式:这会在CMS中添加额外的日志记录。 http://www.onehippo.org/library/development/debug-wicket-ajax-in-the-cms.html http://www.onehippo.org/library/development/debug-wicket-ajax-in-the-cms.html
  • you can also try to break the configuration by putting the wrong class name: if you don't have a ClassNotFound then you know your configuration is wrong and/or not picked-up. 您还可以尝试通过输入错误的类名称来破坏配置:如果您没有ClassNotFound,则您知道配置错误和/或未使用。

HTH. HTH。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM