Magnolia CMS 6.2 自定义字段
Magnolia CMS 6.2 Custom Field
如何从 JCR 获取 Magnolia 6.2 版自定义字段工厂的项目值?
在早期版本的 Magnolia 中,Abstract FieldFactory 实现中是 属性 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());
Here为测试例
@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;
}
如何从 JCR 获取 Magnolia 6.2 版自定义字段工厂的项目值? 在早期版本的 Magnolia 中,Abstract FieldFactory 实现中是 属性 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());
Here为测试例
@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;
}