Magnolia CMS 6.2自定义字段



如何从JCR中获得木兰6.2版自定义字段工厂的项目值?在Magnolia的早期版本中,抽象字段工厂的实现是Item属性Item。从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;
}
}

可以将ValueContext<Node>注入到现场工厂构造函数中。然后你可以通过

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

下面是一个测试示例。

@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;
}

最新更新