【问题标题】:How to fill out Dynamic Dropdown in Hippo CMS with dynamic values?如何用动态值填写 Hippo CMS 中的动态下拉列表?
【发布时间】:2015-09-06 16:55:18
【问题描述】:

我的文档类型包含“动态下拉”字段,我想用一些动态数据填充它。我不知道该怎么做(找不到任何足够的信息、文档、关于此的示例)。从我发现的链接中,我能够做以下事情:

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

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) 在 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) 对于文档类型的字段 /hippo:namespaces/cms/TestItem/editor:templates/_default_/dynamicdropdown,提供以下属性:(使用控制台)
plugin.class= com.test.cms.components.TestPlugin

但仍然无法动态获取数据。什么都没有发生。
我正在使用 HippoCMS 10 社区版

【问题讨论】:

    标签: dynamic plugins content-management-system selection hippocms


    【解决方案1】:

    你完全在正确的轨道上,我找不到任何明显的原因为什么这不起作用。你能仔细检查一些事情吗?

    • 在日志中查找错误,可能在 CMS 的早期启动时。可能在引导过程中出现错误。
    • 在 CMS 中激活开发模式:这会在 CMS 中添加额外的日志记录。 http://www.onehippo.org/library/development/debug-wicket-ajax-in-the-cms.html
    • 您也可以尝试通过输入错误的类名来破坏配置:如果您没有 ClassNotFound,那么您就知道您的配置错误和/或未被选中。

    HTH。

    【讨论】:

    • 谢谢!我启用了额外的日志记录,现在我有下一个日志:
      [AbstractRepeater.onBeforeRender:134] 中继器 org.apache.wicket .markup.repeater.RepeatingView:selectDropdownItem 的子组件的子组件具有 dropdownListViewItem 的非安全子 ID -0。安全子 ID 必须仅由数字组成。
    猜你喜欢
    • 1970-01-01
    • 2021-09-12
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 2020-11-12
    相关资源
    最近更新 更多