You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Bernard <bh...@gmail.com> on 2015/06/08 09:12:11 UTC

How to get FormComponent value outside Model

Hi,

I hope someone can help me learn and understand this.

After Form#onSubmit(), without any error on the Wicket side, the service
tier has a validation error that belongs to a known FormComponent. With a
class extending  AbstractFormValidator, the known FormComponent gets the
error which is shown in context correctly. Great.

However, after re-display of the page with the error, the original input is
lost from the field because the service method does not return it and it is
not in the model. I guess this is by design and it makes sense to me. So in
order to fix this, the service would need to return the erroneous value in
the erroneous field.

My question is what the correct Wicket pattern would be for this type of
use case. Can I get the erroneous user input back from Wicket at this stage
(after onSubmit() ) and push it back into the FormComponent?

The use case by the way is a model object that has two ID fields one
transient and one persisted while there is only one FormComponent for it
that has a custom IModel with getters and setters that are connected to the
two ID fields alternatively. This solves the problem where an ID is either
user generated or system generated depending on some entity type. BTW I
feel that Wicket lets me handle this very well.

Many thanks.

Bernard

Re: How to get FormComponent value outside Model

Posted by Bernard <bh...@gmail.com>.
Hi Sven,

> and the user input is cleared.

Thank you. The user input is cleared, and this is definite and there is no
way to get it from Wicket at this stage (after onSubmit()). I take this as
your definite answer.

Re your question. The domain model does not strictly follow the beans
standard. It has two ID fields one persistent (the final, definite ID field
that may be service tier generated) and one transient that the user can
enter values into. It has an asymetric custom Wicket IModel. It solves a
mildly tricky problem that I described in my 1st post. The consequence is
that the erroneous value is lost because it does not get transferred into
the persistent id field where only valid values can exist. I can solve the
problem on the Wicket side by checking for the error and only then fetching
the value from the transient erroneous field in the model.

You see I have some messy logic here which might be ok, or there might be a
better Wicket way. Therefore I wanted to ask in the user group whether I am
missing something. Again thanks very much. In any case, Wicket is a very
elegant framework that lets one do almost everything with great confidence,
last not least because of your great support. Wicket 7 is the best release
I have ever seen. I am impressed by the improved session expiry behavior,
the best kept secret of this release.

Regards,

Bernard

On Mon, Jun 8, 2015 at 9:22 PM, Sven Meier <sv...@meiers.net> wrote:

> Hi Bernard,
>
> > applicable Wicket pattern which is different from validation before
> #onSubmit()
>
> for Wicket validation happens before submit: the values are set into the
> models and the user input is cleared.
>
> There's something I don't understand - you've written:
>
> > However, after re-display of the page with the error, the original input
> is lost from the field because the service
> > method does not return it and it is not in the model.
>
> The entered value should already be in your domain object, before
> #onSubmit() is called.
> Or are you replacing the whole model object with the return value of the
> service method? In that case you should transfer the values between these
> two objects by yourself.
>
> Regards
> Sven
>
>
>
> On 08.06.2015 10:53, Bernard wrote:
>
>> Hi Sven,
>> The form validator is not added to the form. It just helps to display the
>> error after #onSubmit() which I am sure is called otherwise the service
>> method would not get called. It is the return of the service method that
>> creates the error response. That is why I am keen on learning about an
>> applicable Wicket pattern which is different from validation before
>> #onSubmit().
>>
>> Regards,
>>
>> Bernard
>>
>> On Mon, Jun 8, 2015 at 8:02 PM, Sven Meier <sv...@meiers.net> wrote:
>>
>>  Hi,
>>>
>>>   After Form#onSubmit(), without any error on the Wicket side, the
>>> service
>>>
>>>> tier has a validation error that belongs to a known FormComponent. With
>>>> a
>>>> class extending  AbstractFormValidator, the known FormComponent gets the
>>>> error which is shown in context correctly
>>>>
>>>>  if a FormValidator reports an error during validation, #onSubmit() will
>>> not be called and the input will stay in the field.
>>>
>>> Are you adding the FormValidator to the form, or are you triggering its
>>> validation by yourself?
>>>
>>> Regards
>>> Sven
>>>
>>>
>>>
>>> On 08.06.2015 09:12, Bernard wrote:
>>>
>>>  Hi,
>>>>
>>>> I hope someone can help me learn and understand this.
>>>>
>>>> After Form#onSubmit(), without any error on the Wicket side, the service
>>>> tier has a validation error that belongs to a known FormComponent. With
>>>> a
>>>> class extending  AbstractFormValidator, the known FormComponent gets the
>>>> error which is shown in context correctly. Great.
>>>>
>>>> However, after re-display of the page with the error, the original input
>>>> is
>>>> lost from the field because the service method does not return it and it
>>>> is
>>>> not in the model. I guess this is by design and it makes sense to me. So
>>>> in
>>>> order to fix this, the service would need to return the erroneous value
>>>> in
>>>> the erroneous field.
>>>>
>>>> My question is what the correct Wicket pattern would be for this type of
>>>> use case. Can I get the erroneous user input back from Wicket at this
>>>> stage
>>>> (after onSubmit() ) and push it back into the FormComponent?
>>>>
>>>> The use case by the way is a model object that has two ID fields one
>>>> transient and one persisted while there is only one FormComponent for it
>>>> that has a custom IModel with getters and setters that are connected to
>>>> the
>>>> two ID fields alternatively. This solves the problem where an ID is
>>>> either
>>>> user generated or system generated depending on some entity type. BTW I
>>>> feel that Wicket lets me handle this very well.
>>>>
>>>> Many thanks.
>>>>
>>>> Bernard
>>>>
>>>>
>>>>  ---------------------------------------------------------------------
>>> 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: How to get FormComponent value outside Model

Posted by Sven Meier <sv...@meiers.net>.
Hi Bernard,

 > applicable Wicket pattern which is different from validation before 
#onSubmit()

for Wicket validation happens before submit: the values are set into the 
models and the user input is cleared.

There's something I don't understand - you've written:

 > However, after re-display of the page with the error, the original 
input is lost from the field because the service
 > method does not return it and it is not in the model.

The entered value should already be in your domain object, before 
#onSubmit() is called.
Or are you replacing the whole model object with the return value of the 
service method? In that case you should transfer the values between 
these two objects by yourself.

Regards
Sven


On 08.06.2015 10:53, Bernard wrote:
> Hi Sven,
> The form validator is not added to the form. It just helps to display the
> error after #onSubmit() which I am sure is called otherwise the service
> method would not get called. It is the return of the service method that
> creates the error response. That is why I am keen on learning about an
> applicable Wicket pattern which is different from validation before
> #onSubmit().
>
> Regards,
>
> Bernard
>
> On Mon, Jun 8, 2015 at 8:02 PM, Sven Meier <sv...@meiers.net> wrote:
>
>> Hi,
>>
>>   After Form#onSubmit(), without any error on the Wicket side, the service
>>> tier has a validation error that belongs to a known FormComponent. With a
>>> class extending  AbstractFormValidator, the known FormComponent gets the
>>> error which is shown in context correctly
>>>
>> if a FormValidator reports an error during validation, #onSubmit() will
>> not be called and the input will stay in the field.
>>
>> Are you adding the FormValidator to the form, or are you triggering its
>> validation by yourself?
>>
>> Regards
>> Sven
>>
>>
>>
>> On 08.06.2015 09:12, Bernard wrote:
>>
>>> Hi,
>>>
>>> I hope someone can help me learn and understand this.
>>>
>>> After Form#onSubmit(), without any error on the Wicket side, the service
>>> tier has a validation error that belongs to a known FormComponent. With a
>>> class extending  AbstractFormValidator, the known FormComponent gets the
>>> error which is shown in context correctly. Great.
>>>
>>> However, after re-display of the page with the error, the original input
>>> is
>>> lost from the field because the service method does not return it and it
>>> is
>>> not in the model. I guess this is by design and it makes sense to me. So
>>> in
>>> order to fix this, the service would need to return the erroneous value in
>>> the erroneous field.
>>>
>>> My question is what the correct Wicket pattern would be for this type of
>>> use case. Can I get the erroneous user input back from Wicket at this
>>> stage
>>> (after onSubmit() ) and push it back into the FormComponent?
>>>
>>> The use case by the way is a model object that has two ID fields one
>>> transient and one persisted while there is only one FormComponent for it
>>> that has a custom IModel with getters and setters that are connected to
>>> the
>>> two ID fields alternatively. This solves the problem where an ID is either
>>> user generated or system generated depending on some entity type. BTW I
>>> feel that Wicket lets me handle this very well.
>>>
>>> Many thanks.
>>>
>>> Bernard
>>>
>>>
>> ---------------------------------------------------------------------
>> 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: How to get FormComponent value outside Model

Posted by Bernard <bh...@gmail.com>.
Hi Sven,
The form validator is not added to the form. It just helps to display the
error after #onSubmit() which I am sure is called otherwise the service
method would not get called. It is the return of the service method that
creates the error response. That is why I am keen on learning about an
applicable Wicket pattern which is different from validation before
#onSubmit().

Regards,

Bernard

On Mon, Jun 8, 2015 at 8:02 PM, Sven Meier <sv...@meiers.net> wrote:

> Hi,
>
>  After Form#onSubmit(), without any error on the Wicket side, the service
>> tier has a validation error that belongs to a known FormComponent. With a
>> class extending  AbstractFormValidator, the known FormComponent gets the
>> error which is shown in context correctly
>>
>
> if a FormValidator reports an error during validation, #onSubmit() will
> not be called and the input will stay in the field.
>
> Are you adding the FormValidator to the form, or are you triggering its
> validation by yourself?
>
> Regards
> Sven
>
>
>
> On 08.06.2015 09:12, Bernard wrote:
>
>> Hi,
>>
>> I hope someone can help me learn and understand this.
>>
>> After Form#onSubmit(), without any error on the Wicket side, the service
>> tier has a validation error that belongs to a known FormComponent. With a
>> class extending  AbstractFormValidator, the known FormComponent gets the
>> error which is shown in context correctly. Great.
>>
>> However, after re-display of the page with the error, the original input
>> is
>> lost from the field because the service method does not return it and it
>> is
>> not in the model. I guess this is by design and it makes sense to me. So
>> in
>> order to fix this, the service would need to return the erroneous value in
>> the erroneous field.
>>
>> My question is what the correct Wicket pattern would be for this type of
>> use case. Can I get the erroneous user input back from Wicket at this
>> stage
>> (after onSubmit() ) and push it back into the FormComponent?
>>
>> The use case by the way is a model object that has two ID fields one
>> transient and one persisted while there is only one FormComponent for it
>> that has a custom IModel with getters and setters that are connected to
>> the
>> two ID fields alternatively. This solves the problem where an ID is either
>> user generated or system generated depending on some entity type. BTW I
>> feel that Wicket lets me handle this very well.
>>
>> Many thanks.
>>
>> Bernard
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to get FormComponent value outside Model

Posted by Sven Meier <sv...@meiers.net>.
Hi,

>After Form#onSubmit(), without any error on the Wicket side, the service
>tier has a validation error that belongs to a known FormComponent. With a
>class extending  AbstractFormValidator, the known FormComponent gets the
>error which is shown in context correctly

if a FormValidator reports an error during validation, #onSubmit() will not be called and the input will stay in the field.

Are you adding the FormValidator to the form, or are you triggering its validation by yourself?

Regards
Sven


On 08.06.2015 09:12, Bernard wrote:
> Hi,
>
> I hope someone can help me learn and understand this.
>
> After Form#onSubmit(), without any error on the Wicket side, the service
> tier has a validation error that belongs to a known FormComponent. With a
> class extending  AbstractFormValidator, the known FormComponent gets the
> error which is shown in context correctly. Great.
>
> However, after re-display of the page with the error, the original input is
> lost from the field because the service method does not return it and it is
> not in the model. I guess this is by design and it makes sense to me. So in
> order to fix this, the service would need to return the erroneous value in
> the erroneous field.
>
> My question is what the correct Wicket pattern would be for this type of
> use case. Can I get the erroneous user input back from Wicket at this stage
> (after onSubmit() ) and push it back into the FormComponent?
>
> The use case by the way is a model object that has two ID fields one
> transient and one persisted while there is only one FormComponent for it
> that has a custom IModel with getters and setters that are connected to the
> two ID fields alternatively. This solves the problem where an ID is either
> user generated or system generated depending on some entity type. BTW I
> feel that Wicket lets me handle this very well.
>
> Many thanks.
>
> Bernard
>


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