Hi,

Use a custom IConverter instead - override TextArea#getConverter(Class) method.
Conversion of data is part of form submit process and if it fails with
org.apache.wicket.util.convert.ConversionException then the model of
that component is not updated and Form#onError() will be called. Point
4) below will be automatically handled for you by Wicket.

On Wed, Apr 25, 2012 at 3:18 PM, Tom Eugelink <t...@tbee.org> wrote:
>
> 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: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to