[英]Magnolia CMS 6.2 Custom Field
在 Magnolia 6.2 版中,如何從 JCR 獲取自定義字段工廠的項目值? 在早期版本的 Magnolia 中,在 Abstract FieldFactory 實現中是屬性 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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.