Assuming that you don't set a model for the FormComponet won't Wicket fail
back to the CompountPropertyModel of the form?
Who will perform the conversion then?
I only override FormComponentPanel#convertInput() when I force my clients to
provide the model for my FormComponentPanel and even then I delegate the
call to another form component :)
e.g.
/**
* {@link FormComponentPanel} that hosts the label and form component with a
shared model.<br>
* The label can be aligned around the form field given the {@link LABEL}
value constants.
*
* @param <F, M>
* F = The form field type (e.g. TextField, CheckBox etc.)
* M = The model object type of the form field
*/
public class LabeledFormField<F extends LabeledWebMarkupContainer, M>
extends FormComponentPanel<M> {
...
public LabeledFormField(String id, IModel<M> model, ...) {
...
}
...
/**
* Propagate changes into the real valid model via the
FormComponentPanel.convertInput() method.
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
protected void convertInput() {
FormComponent<?> formComponent = ...
if(formComponent != null) {
setConvertedInput((M)formComponent.getConvertedInput());
}
}
...
}
Above class warps around all the form field I use to ensure that
accessibility is supported.
I did so per the recommendation of Wicket:
http://ci.apache.org/projects/wicket/apidocs/6.0.x/org/apache/wicket/markup/
html/form/FormComponentPanel.html
It is recommended that you override FormComponent.convertInput() and let it
set the value that represents the compound value of the nested components.
Often, this goes hand-in-hand with overriding Component.onBeforeRender(),
where you would analyze the model value, break it up and distribute the
appropriate values over the child components.
But if you have a CompoundPropertyModel, do you really need to do all this
conversion?
Wouldn't the form component wrapped inside the panel handle it itself?
I had to delegate the call because I don't always use a
CompoundProeprtyModel.
~ Thank you,
Paul Bors
-----Original Message-----
From: Joachim Schrod [mailto:[email protected]]
Sent: Thursday, December 06, 2012 2:05 PM
To: [email protected]
Subject: Re: Model is null after submit, using FormComponentPanel
Paul Bors wrote:
> I would suggest overriding FormComponentPanel#convertInput() only if
> your domain object can't be easily converted by Wicket given the model you
have.
>
> If you're using CompoundPropertyModel and set the model on your
> FormComponentPanel then your TextField ID and type should be all you
> need for wicket to know which getter/setter to call.
Really? That's not possible in an 1.4-based application, IMHO.
FormComponentPanel is a FormComponent, i.e., it participates in conversion,
validation, and update Model. When that FormComponentPanel has an associated
model, e.g., a CompoundPropertyModel, its getInputAsArray() will return
null, null will be stored as convertedInput, and updateModel() will set the
CompoundPropertyModel's object to that null value.
When sub-widgets of a FormComponentPanel do all the work necessary, and the
FormComponentPanel has a model of its own, I often override
updateModel() to be an empty method, to prevent the behavior named above
from happening.
Best,
Joachim
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Joachim Schrod, Roedermark, Germany
Email: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]