Hi all,
One of our suppliers provides a visual javascript configurator for their
services. I would like to create a custom Wicket component for rendering
but also for saving the data in a domain object.
The javascript to be added to the component is
<script>const inputConfiguration = { "organisation": { "name":
"MyOrganisationName", "centralPhoneNumber": "0401234567", }, }; function
okCallBack(configuration) { alert("OK!\n" +
JSON.stringify(configuration, null, 2)); } function cancelCallBack() {
alert("CANCEL!"); } Configurator.create('configuratorhtmlelementid',
inputConfiguration, okCallBack, cancelCallBack); </script>
The configurator has 2 buttons (ok, cancel) which will call the callback
methods. I was able to render the configurator but now I need the
callback methods to update the related domain object. I don't know how
to 'bind' the callback methods to a Wicket component that will update
the domain object.
The file/class structure I wanted to use is as follows.
A view model class (Configurator) for which I want the custom component
to be rendered.
@XmlRootElement(name = "configurator")
@javax.xml.bind.annotation.XmlType( propOrder = { "generatedConfig" } )
public class Configurator { @XmlElement @Getter @Setter private String
generatedConfig; }
A panel to render the form containing the configurator-element
public class ConfiguratorPanel extends PanelAbstract<ScalarModel> {
public ConfiguratorPanel(String id, final ScalarModel model){ super(id,
model); buildGui(); } private void buildGui() { ScalarModel model =
getModel(); add(new ConfiguratorForm("inputForm", getSettings(),
model)); } @Override public void renderHead(final IHeaderResponse
response){ super.renderHead(response);
response.render(JavaScriptHeaderItem.forReference(new
JavaScriptResourceReference(ConfiguratorForm.class,
"configurator-lib.js"))); // external js-library
response.render(JavaScriptHeaderItem.forReference(new
JavaScriptResourceReference(ConfiguratorForm.class,
"configurator-panel.js"))); // file containing above javascript to
initialize the configurator } }
ConfiguratorPanel.html
<!DOCTYPE html> <html xmlns:wicket="http://wicket.apache.org"> <body>
<wicket:panel> <form wicket:id="inputForm" method="post"> <div
id="configuratorhtmlelementid"></div> </form> </wicket:panel> </body>
</html>
The methods 'okCallBack' and 'cancelCallBack' somehow have to be
'generated' before the configurator is created from javascript and have
to update the Configurator view model. I tried creating a form like
PropertyEditForm for generating the callbacks but I can't find out how
to do it.
public class ConfiguratorForm extends FormAbstract<ObjectAdapter> { .... }
Anyone having an idea about this? Although it's not really an Apache
Isis question I'm hoping someone could give me some directions for how
to do this.
Thanks, Erik