木兰CMS 6.2自定义字段

发布于 2025-01-28 14:29:23 字数 1298 浏览 2 评论 0原文

如何从JCR中获取Magnolia 6.2版的Custom Field Factory的项目值? 在较早版本的木兰中,在抽象的现场捕获实现中是属性项目。由于版本6.2。它不再在那里。

public class CustomFieldFactory extends AbstractFieldFactory<String, CustomFieldDefinition> {
    @Inject
    public CustomFieldFactory(CustomFieldDefinition definition, ComponentProvider componentProvider) {
        super(definition, componentProvider);
    }

    public Component createFieldComponent() {
        Object field;
        if (((CustomFieldDefinition)this.getDefinition()).getRows() > 1) {
            TextArea textArea = new TextArea();
            textArea.setRows(((SalesVolumeFromDataHubFieldDefinition)this.getDefinition()).getRows());
            field = textArea;
        } else {
            field = new TextField();
        }
  
        if (((CustomFieldDefinition)this.getDefinition()).getMaxLength() != -1) {
            ((AbstractTextField)field).setMaxLength(((CustomFieldDefinition)this.getDefinition()).getMaxLength());
            MaxLengthIndicatorExtension.extend((AbstractTextField)field);
        }

        ((AbstractTextField)field).setPlaceholder(((CustomFieldDefinition)this.getDefinition()).getPlaceholder());
        return (Component)field;
    }
}

How can I get the item value from JCR for custom field factory in Magnolia version 6.2?
In the earlier version of Magnolia, in Abstract FieldFactory implementations was the property Item item. Since version 6.2. it is no longer there.

public class CustomFieldFactory extends AbstractFieldFactory<String, CustomFieldDefinition> {
    @Inject
    public CustomFieldFactory(CustomFieldDefinition definition, ComponentProvider componentProvider) {
        super(definition, componentProvider);
    }

    public Component createFieldComponent() {
        Object field;
        if (((CustomFieldDefinition)this.getDefinition()).getRows() > 1) {
            TextArea textArea = new TextArea();
            textArea.setRows(((SalesVolumeFromDataHubFieldDefinition)this.getDefinition()).getRows());
            field = textArea;
        } else {
            field = new TextField();
        }
  
        if (((CustomFieldDefinition)this.getDefinition()).getMaxLength() != -1) {
            ((AbstractTextField)field).setMaxLength(((CustomFieldDefinition)this.getDefinition()).getMaxLength());
            MaxLengthIndicatorExtension.extend((AbstractTextField)field);
        }

        ((AbstractTextField)field).setPlaceholder(((CustomFieldDefinition)this.getDefinition()).getPlaceholder());
        return (Component)field;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花之痕靓丽 2025-02-04 14:29:24

您可以将valueContext&lt; node&gt;注入现场工厂构造函数。
然后,您可以通过

Node dialogNode = valueContext.getSingleOrThrow();
Property thisFieldProperty = dialogNode.getProperty(getDefinition().getName());

在这里是一个测试示例。

You can inject ValueContext<Node> into the field factory constructor.
Then you can retrieve it via

Node dialogNode = valueContext.getSingleOrThrow();
Property thisFieldProperty = dialogNode.getProperty(getDefinition().getName());

Here is a test example.

我为君王 2025-02-04 14:29:24
@Override
protected GenericButton createFieldComponent() {
    Node node = valueContext.getSingleOrThrow();
    GenericButton button = new GenericButton();
    button.setButtonCaption("Senden");
    button.setVisible(true);
    button.getButton().addClickListener(createButtonClickListener(node));

    return button;
}
@Override
protected GenericButton createFieldComponent() {
    Node node = valueContext.getSingleOrThrow();
    GenericButton button = new GenericButton();
    button.setButtonCaption("Senden");
    button.setVisible(true);
    button.getButton().addClickListener(createButtonClickListener(node));

    return button;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文