Commit df71d50b authored by Canh Ngo's avatar Canh Ngo

HSTCONFIGEDIT-188: fixed by loading and saving editor-bean object upon changes...

HSTCONFIGEDIT-188: fixed by loading and saving editor-bean object upon changes in plugin's JCR node model
parent 4a4ddb64
......@@ -28,7 +28,6 @@ import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.StringResourceModel;
import org.hippoecm.frontend.PluginRequestTarget;
import org.hippoecm.frontend.dialog.IDialogService;
......@@ -53,7 +52,8 @@ public abstract class BasicEditorPlugin<K extends EditorBean> extends EditorPlug
private final FeedbackPanel feedback;
protected final Form<K> form;
private final LoadableDetachableModel<K> beanModel;
private K editorBeanObject;
protected AjaxSubmitLink saveLink;
......@@ -62,29 +62,9 @@ public abstract class BasicEditorPlugin<K extends EditorBean> extends EditorPlug
public BasicEditorPlugin(IPluginContext context, IPluginConfig config) {
super(context, config);
beanModel = new LoadableDetachableModel<K>() {
@Override
protected K load() {
IModel model = getModel();
if (model instanceof JcrNodeModel) {
return dao.load((JcrNodeModel) model);
} else {
log.error("Cannot load bean object model due to the model of '{}' is not the JcrNodeModel object",
BasicEditorPlugin.this.getClass().getName());
return null;
}
}
editorBeanObject = getEditorBeanObject();
@Override
protected void onDetach() {
final K object = getObject();
if (object != null) {
object.detach();
}
}
};
IModel<K> formModel = new CompoundPropertyModel<>(beanModel);
IModel<K> formModel = new CompoundPropertyModel<>(editorBeanObject);
add(form = new Form<>("editor", formModel));
add(saveLink = new AjaxSubmitLink("save", form) {
......@@ -182,6 +162,17 @@ public abstract class BasicEditorPlugin<K extends EditorBean> extends EditorPlug
add(downLink);
}
private K getEditorBeanObject() {
IModel model = getModel();
if (model instanceof JcrNodeModel) {
return dao.load((JcrNodeModel) model);
} else {
log.error("Cannot load bean object due to the model of '{}' is not the JcrNodeModel object",
BasicEditorPlugin.this.getClass().getName());
return null;
}
}
@Override
protected void onStart() {
super.onStart();
......@@ -199,6 +190,8 @@ public abstract class BasicEditorPlugin<K extends EditorBean> extends EditorPlug
@Override
protected void onModelChanged() {
updateFormModel();
IModel model = getModel();
if (model instanceof JcrNodeModel) {
nodeSort.setModel((JcrNodeModel) model);
......@@ -206,6 +199,15 @@ public abstract class BasicEditorPlugin<K extends EditorBean> extends EditorPlug
super.onModelChanged();
}
private void updateFormModel() {
if (editorBeanObject != null) {
editorBeanObject.detach();
}
editorBeanObject = getEditorBeanObject();
form.setModelObject(editorBeanObject);
}
@Override
public void render(PluginRequestTarget target) {
if (target != null && feedback.anyMessage()) {
......@@ -250,15 +252,17 @@ public abstract class BasicEditorPlugin<K extends EditorBean> extends EditorPlug
}
public K getBean() {
return beanModel.getObject();
return editorBeanObject;
}
@Override
public void detachModels() {
nodeSort.detach();
if (beanModel != null) {
beanModel.detach();
if (editorBeanObject != null) {
editorBeanObject.detach();
}
super.detachModels();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment