我想在下拉菜单中自动保存下拉选项,而不单击保存按钮(保存按钮被禁用)吗?我该怎么办?
答案 0 :(得分:0)
在通常情况下,当您需要为所有项目模型实现对管理角度的这种要求时,我建议您在编辑器UI呈现期间添加事件侦听器。
为此,您需要实现自定义节渲染器:
public class CustomEditorAreaSectionRenderer extends com.hybris.cockpitng.widgets.editorarea.renderer.impl.DefaultEditorAreaSectionRenderer {
@Autowired
private ModelService modelService;
@Override
protected void processEditorBeforeComposition(final Editor editor, final DataType genericType, final WidgetInstanceManager widgetInstanceManager, final Attribute attribute, final Object object) {
editor.addEventListener("onRequiredAction", (org.zkoss.zk.ui.event.Event event) -> {
modelService.save(object);
});
}
}
默认实现声明为spring bean,因此您可以轻松地注入自定义实现。例如,通过editorAreaSectionRenderer
的别名。默认声明如下:
<alias name="defaultEditorAreaTabRenderer" alias="editorAreaTabRenderer"/>
<bean id="defaultEditorAreaTabRenderer"
class="com.hybris.cockpitng.widgets.editorarea.renderer.impl.DefaultEditorAreaTabRenderer"
parent="abstractEditorAreaComponentRenderer" scope="prototype">
<property name="editorAreaSectionRenderer" ref="editorAreaSectionRenderer"/>
</bean>
<alias name="defaultEditorAreaSectionRenderer" alias="editorAreaSectionRenderer"/>
<bean id="defaultEditorAreaSectionRenderer"
class="com.hybris.cockpitng.widgets.editorarea.renderer.impl.DefaultEditorAreaSectionRenderer"
parent="abstractEditorAreaComponentRenderer" scope="prototype">
<property name="editorAreaPanelRenderer" ref="editorAreaPanelRenderer"/>
<property name="validationRenderer" ref="validationRenderer"/>
</bean>
请注意,OOTB保存过程是一个非常复杂的操作,应谨慎执行。看看默认情况下如何在com.hybris.cockpitng.widgets.baseeditorarea.DefaultEditorAreaController#saveObject