I found a way to make this work (though I worry the solution might be a
little fragile).
Basically, I'm overriding getInputAsArray() in my wrapper EntityLink,
delegating to a hidden text field; then, in onBeforeRender() I check if
there is input, and if not then infer that clearInput must've been
called on and so zap the value of the hidden text field.
If anyone cares to look at the code, it's on sourceforge:
http://wicketobjects.svn.sourceforge.net/viewvc/wicketobjects/trunk/main/viewer/src/main/java/org/starobjects/wicket/viewer/components/entitylink/EntityLink.java?revision=78&view=markup
Thanks anyway
Dan
Dan Haywood
consultant, mentor, developer, author
agile, ddd, oo, java, .net, sybase
MA, MBCS, CITP, CEng
/mail: /d...@haywood-associates.co.uk <mailto:d...@haywood-associates.co.uk>
/phone: /+44 (0)7961 144286
/book: /Domain Driven Design using Naked Objects
<http://pragprog.com/titles/dhnako>
/blog: /http://danhaywood.com
/linked in: /http://uk.linkedin.com/in/dkhaywood
/twitter: /http://twitter.com/dkhaywood
/sybase: /http://sybtraining.co.uk
On 19/04/2010 13:08, Jeremy Thomerson wrote:
You shouldn't be committing your changes to the actual domain object
until the form is submitted (your ok button).
Jeremy Thomerson
http://www.wickettraining.com
-- sent from a wireless device
------------------------------------------------------------------------
From: Dan Haywood <dkhayw...@gmail.com>
Sent: Monday, April 19, 2010 5:53 AM
To: users@wicket.apache.org
Subject: how to handle clear input for custom FormComponents
Hi all,
I've developed a custom FormComponent (by subclassing
FormComponentPanel) to act as a reference from one object to another
(eg a Customer to an Address), but am having problems figuring out how
to handle clear input (ie, if the user hits the cancel button on the
form).
To explain a little further, the FormComponent is called EntityLink,
and renders the reference (eg the Customer's homeAddress) a
hyperlink. I have a button on the EntityLink panel allowing the user
to perform a search for other objects of the correct type, and then
select it. Doing this updates the EntityLink component, with a
"pending" value (ie of the new homeAddress). If the user hits the OK
button, then the pending value is copied over to the domain object (ie
to the Customer's actual homeAddress property).
In the cancel button's onSubmit() method I'm calling
getForm().clearInput(), which seems to use a visitor to call
clearInput() on all child FormComponent's. The FormComponent's
clearInput() method seems only to set the rawInput to a constant
(NO_RAW_INPUT), which looks like it's a magic value of some kind when
the form component is actually rendered - all rather low level.
I think what I'd like is to eagerly capture this clearInput so that I
can reset my EntityLink's hyperlink back to the original value and
discard the pending value. However, clearInput() is unfortunately
marked as final so there doesn't seem to be any easy way to capture this.
Looking at other implementations of FormComponentPanel (eg
DateTimeField) they are really very little other than wrappers around
simple FormComponents, so they don't offer any real clues.
Can anyone help me here, then?
Thanks
Dan
--
Dan Haywood
consultant, mentor, developer, author
agile, ddd, oo, java, .net, sybase
MA, MBCS, CITP, CEng
/mail: /d...@haywood-associates.co.uk
<mailto:d...@haywood-associates.co.uk>
/phone: /+44 (0)7961 144286
/book: /Domain Driven Design using Naked Objects
<http://pragprog.com/titles/dhnako>
/blog: /http://danhaywood.com
/linked in: /http://uk.linkedin.com/in/dkhaywood
/twitter: /http://twitter.com/dkhaywood
/sybase: /http://sybtraining.co.uk
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org