I've got a form bound to a CompoundPropertyModel. One of the properties
contains a XML document. In order to edit that property, I've added a TextArea
to the form (with the CodeMirror javascript XML editor bound to it), but I need
to convert the XML document property to string and back again. I've implemented
this by creating an anonymous model, like this:
lForm.add(new TextArea<>("services", new IModel<String>()
{
@Override
public void detach()
{
}
@Override
public String getObject()
{
return
JAXBUtil.extractAndSerializeServicesElement(lLicenseJAXB);
}
@Override
public void setObject(String s)
{
try
{
JAXBUtil.parseAndSpliceServicesElement(lLicenseJAXB, s);
}
catch (Exception e)
{
lErrorOccurredAtomicBoolean.set(true);
slf4j.error("Error during submit", e);
error(e.getLocalizedMessage());
}
}
}).setOutputMarkupId(true).setMarkupId("codemirror"));
There are a few question I have:
1. Is this the right way to add such a conversion?
2. Will this model be persisted to the session as well? I of course do not want
that, it just needs to convert.
3. If there is an exception in setObject, I use an AtomicBoolean to register
that, so that the Form.onSubmit knows that something is amiss. Otherwise I get
a big fat exception on the screen or the ssubmit just continues. Is there a
better way?
4. If there is an error, I would like getObject to return the value that was
submitted by the form, so that the user can correct his mistake. Now it always
returns the value before the edit. How to do that?
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]