>
>
> Okay, so the difference with Form.process() is that process() does not
> update at all when one of the FormComponents is invalid, and
> updateFormComponentModels updates all that ARE valid, right? So that's
> usually what you want (and what I want in this case). Thanks for making
> this clear.



Yes if one fails  no  models are updated at all. Only when everything is
going ok
the models are updated.


In Form.process() where this method is called, the form is validated
> first, so conversion took place as a side effect of validation. There I
> can see how it works. Maybe the javadoc of
> Form.updateFormComponentModels should state that Form.validate should be
> called first. Form.validate does state that: "This method is typically
> called before updating any models." which is good.


i changed it to this:

     /**
     * Update the model of all form components using the fields that were
sent with the current
     * request. This method only updates models when the Form.validate() is
called first that takes
     * care of the conversion for the FormComponents.
     *
     * Normally this method will not be called when a validation error
occurs in one of the form
     * components.
     *
     * @see org.apache.wicket.markup.html.form.FormComponent#updateModel()
     */


> We could split up the methods again, like in Form.process()
> > which calls the above validate only. We could split that up in to
> > validateRequired(), validateConversion(), validateXX()
> > but what do we gain then?
> >
>
> Readability!
>
> When a method is called validate() I expect it to validate, and validate
> ONLY. Conversion of input is a side effect of validation.



no checking for required is validation.
type conversion is validation it, validates if it can convert '10.45455dddd'
to an integer..

as you can see in the method:
/**
     * Performs full validation of the form component, which consists of
calling validateRequired(),
     * convertInput(), and validateValidators(). This method should only be
used if the form
     * component needs to be fully validated outside the form process.
     */
    public final void validate()
    {
        validateRequired();
        if (isValid())
        {
            convertInput();

            if (isValid() && isRequired() && getConvertedInput() == null &&
isInputNullable())
            {
                reportRequiredError();
            }

            if (isValid())
            {
                validateValidators();
            }
        }
    }

after every state it also calls isValid() so that it fails early and with a
right error.



> Ehmokay. Do I really need to file a bug for this small documentation
> bug? Done: https://issues.apache.org/jira/browse/WICKET-951



/**
     * Updates this components model from the request, it expects that the
object is already
     * converted through the convertInput() call that is called by the
validate() method when a form
     * is being processed.
     *
     * By default it just does this:
     *
     * <pre>
     * setModelObject(getConvertedInput());
     * </pre>
     *
     * DO NOT CALL THIS METHOD DIRECTLY UNLESS YOU ARE SURE WHAT YOU ARE
DOING. USUALLY UPDATING
     * YOUR MODEL IS HANDLED BY THE FORM, NOT DIRECTLY BY YOU.
     */


> We have this also because it preserves memory, If you have to make an
> > (inner)class instance
> > and a link instance and attach those 2 each other that can consume much
> more
> > memory
> > then when just making a new class and have there one instance.
> >
> I'm not sure I see what you mean, but doesn't the (inner) class also
> need instantiation, consuming just as much memory?



Yes but only 1 instance.. for example:

Link link = new Link()
{
  onClick()
  {
   // do your thing
  }
}

or

Link link = new Link();
link.add(new LinkClickListener()
{
   onClick()
   {
    // do you thing.
   }
});

the second approach makes 2 instances and link has now also a special extra
map to hold the listener.

johan

Reply via email to