You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Brown, Berlin [GCG-PFS]" <Be...@Primerica.com> on 2011/07/29 04:27:08 UTC

getInput and getDefaultModelObject and validation

If I am using some form validator, I notice that getDefaultModelObject
does not have the value from the getInput.  I am assume this
intentional.  Is there a way to force wicket to update the modelObject?
How and when does the modelobject get updated.
 
 
myForm.add(new AbstractFormValidator() {
 
   public void validate() {
 
       String val = component.getInput();  <--- has the correct value
from the request 
       String val2 = component.getModelObject();  <---- does not have
value.
   }
 
});
...
 
In the case above, I could use the proper ajaxbehavior (like onBlur on a
textfield) and the modelObject gets updated.
 
But if I weren't using ajax, is there a way to force wicket to update
the modelObject.

RE: getInput and getDefaultModelObject and validation

Posted by "Brown, Berlin [GCG-PFS]" <Be...@Primerica.com>.
" then your model will have invalid data, and if that is acceptable,
what role does the validator fill then? You might as well do your checks
in onSubmit() at that point..."

I guess it depends, I normally haven't had a need to validate every
individual component.  But I like having all of my model objects with
their values and then doing validation of those values/types before the
form is submitted.

getConvertedInput would work

"what role does the backing object fill" if you can't using them during
your validation.

I guess in some cases you want an override switch to allow the model
object to get updated with the input pre-validation.

...
As a hack, we normally just add ajaxbehaviors on the components and
their values get updated, then I can do form validation with all the
updated models.

-----Original Message-----
From: Wilhelmsen Tor Iver [mailto:TorIverW@arrive.no] 
Sent: Friday, July 29, 2011 5:04 AM
To: users@wicket.apache.org
Subject: RE: getInput and getDefaultModelObject and validation

> Is there a way to force a modelobject update on each individual field 
> and then do my form validation.

It seems you want to use getConvertedInput(). Going via the model to get
the converted value is just a detour when you are in a validator. If you
push data to the model and then decide it is invalid, then your model
will have invalid data, and if that is acceptable, what role does the
validator fill then? You might as well do your checks in onSubmit() at
that point...

>      if (textField1.getInput() == "creditCard") {

You should be aware that this code will most likely fail. Look into
equals().

- Tor Iver

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




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


RE: getInput and getDefaultModelObject and validation

Posted by Wilhelmsen Tor Iver <To...@arrive.no>.
> Is there a way to force a modelobject update on each individual field
> and then do my form validation.

It seems you want to use getConvertedInput(). Going via the model to get the converted value is just a detour when you are in a validator. If you push data to the model and then decide it is invalid, then your model will have invalid data, and if that is acceptable, what role does the validator fill then? You might as well do your checks in onSubmit() at that point...

>      if (textField1.getInput() == "creditCard") {

You should be aware that this code will most likely fail. Look into equals().

- Tor Iver

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


RE: getInput and getDefaultModelObject and validation

Posted by "Brown, Berlin [GCG-PFS]" <Be...@Primerica.com>.
I guess there are cases where you want to use an AbstractFormValidator
and run validation on a form before it is submitted and want to address
those fields before they are submitted.  It would be nice if the
modelobject were updated.

Let's say you have 100 textfields attached to a form, you want to
validate some of the fields, all at once (say using FormValidator
attached to the form),

Is there a way to force a modelobject update on each individual field
and then do my form validation.  (I guess the only way is through ajax
events on each field).

E.g.

Form.add(new TextField);
Form.add(new TextField);
Form.add(new TextField);
Form.add(new TextField);
Form.add(new TextField);

Form.add(new AbstractFormValidator() {
   onValidate() {
      if (textField1.getInput() == "creditCard") {
      }
   }
});
...

With the code above, I have to do all of my form validation without my
desired type.

-----Original Message-----
From: Wilhelmsen Tor Iver [mailto:TorIverW@arrive.no] 
Sent: Friday, July 29, 2011 3:20 AM
To: users@wicket.apache.org
Subject: RE: getInput and getDefaultModelObject and validation

> If I am using some form validator, I notice that getDefaultModelObject

> does not have the value from the getInput.  I am assume this 
> intentional.  Is there a way to force wicket to update the
modelObject?

Yes, form component models are not updated until they pass validation,
that is very intentional. :)

(E.g. if you have a Date text field and someone types "beer", what would
you expect to be written to the model?)

> How and when does the modelobject get updated.
 
When all validation succeeds and it progresses into a submit.

> But if I weren't using ajax, is there a way to force wicket to update 
> the modelObject.

That will happen automatically after validation passes. Validation
should ideally only check inputs and give any errors.

- Tor Iver

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




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


RE: getInput and getDefaultModelObject and validation

Posted by Wilhelmsen Tor Iver <To...@arrive.no>.
> If I am using some form validator, I notice that getDefaultModelObject
> does not have the value from the getInput.  I am assume this
> intentional.  Is there a way to force wicket to update the modelObject?

Yes, form component models are not updated until they pass validation, that is very intentional. :)

(E.g. if you have a Date text field and someone types "beer", what would you expect to be written to the model?)

> How and when does the modelobject get updated.
 
When all validation succeeds and it progresses into a submit.

> But if I weren't using ajax, is there a way to force wicket to update
> the modelObject.

That will happen automatically after validation passes. Validation should ideally only check inputs and give any errors.

- Tor Iver

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