You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Martin Makundi <ma...@koodaripalvelut.com> on 2009/07/07 15:57:11 UTC

Prefill form not model?

Hi!

What is the proper way to prefill a wicket form (not poke the model
before submit!!!)?

I have used a hack:

      Field rawInputField = FormComponent.class.getDeclaredField("rawInput");
      rawInputField.setAccessible(true);
      rawInputField.set(component, description);

Is there a better way?

**
Martin

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


Re: Prefill form not model?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
> In your opinion.  Hibernate supports merging (if that's what you're using).
> Why not edit the object in a detached state (not in the session)?
> Then, when you want to update it, you call update()?

If there was only one simple object yes... but there is a whole
collaboration diagram of objects. Keeping the state of what is
actually updated by the user and what has only default values would
just result in a jungle of hard-to-debug bugs...

> write a model that returns your default value in getobject and updates
> the object in setobject

This sounds good in principle, but how do I know when to stop giving
the default value? I will need to have a check also at setObject to
turn off the default value? Still the hack sounds to me like a simpler
solution: Why not give FormComponent a method
formComponent.set'Default'RawValue(xx)?

**
Martin

>
> ---------------------------------------------------------------------
> 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: Prefill form not model?

Posted by James Carman <jc...@carmanconsulting.com>.
On Tue, Jul 7, 2009 at 10:59 AM, Martin Makundi
<ma...@koodaripalvelut.com> wrote:
>
> The hack is cleaner

In your opinion.  Hibernate supports merging (if that's what you're using).

Why not edit the object in a detached state (not in the session)?
Then, when you want to update it, you call update()?  If the edit
never succeeds, then you never send those values to the db.

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


Re: Prefill form not model?

Posted by Johan Compagner <jc...@gmail.com>.
The hack is awful

Just have a detachable model that holds on first render the defaults
then when a submit is done populate the object (another) that you want

On 07/07/2009, Martin Makundi <ma...@koodaripalvelut.com> wrote:
> The hack is cleaner
>
> 2009/7/7 James Carman <jc...@carmanconsulting.com>:
>> On Tue, Jul 7, 2009 at 10:51 AM, Martin Makundi <
>> martin.makundi@koodaripalvelut.com> wrote:
>>
>>> > Typically to prefill a form you have the backing model object have
>>> > sensible defaults.  i.e., a form that edits a person is given a
>>> > person, and the person object has it's gender set to "male" as a
>>> > default - that is reflected in your form when it is rendered.
>>>
>>> The problem is that it is not a NEW object. It is an old object with
>>> "proposed new values" which the user must SUBMIT in order to be stored
>>> into the object etc.
>>
>>
>> So, create a new object and merge it upon success?
>>
>
> ---------------------------------------------------------------------
> 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: Prefill form not model?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
The hack is cleaner

2009/7/7 James Carman <jc...@carmanconsulting.com>:
> On Tue, Jul 7, 2009 at 10:51 AM, Martin Makundi <
> martin.makundi@koodaripalvelut.com> wrote:
>
>> > Typically to prefill a form you have the backing model object have
>> > sensible defaults.  i.e., a form that edits a person is given a
>> > person, and the person object has it's gender set to "male" as a
>> > default - that is reflected in your form when it is rendered.
>>
>> The problem is that it is not a NEW object. It is an old object with
>> "proposed new values" which the user must SUBMIT in order to be stored
>> into the object etc.
>
>
> So, create a new object and merge it upon success?
>

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


Re: Prefill form not model?

Posted by James Carman <jc...@carmanconsulting.com>.
On Tue, Jul 7, 2009 at 10:51 AM, Martin Makundi <
martin.makundi@koodaripalvelut.com> wrote:

> > Typically to prefill a form you have the backing model object have
> > sensible defaults.  i.e., a form that edits a person is given a
> > person, and the person object has it's gender set to "male" as a
> > default - that is reflected in your form when it is rendered.
>
> The problem is that it is not a NEW object. It is an old object with
> "proposed new values" which the user must SUBMIT in order to be stored
> into the object etc.


So, create a new object and merge it upon success?

Re: Prefill form not model?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
>> having read the thread I didn't get why you can not modify the object
>> itself.

Actually.. the only GOOD reason I can come up with is that by setting
the default value into RAWINPUT, it will be validated when the form is
submitted.

**
Martin

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


Re: Prefill form not model?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
OSiV ?

> having read the thread I didn't get why you can not modify the object
> itself.

Premature optimization ;) ?

Coming to think about it again (this way, the opposite way) there is
nothing bad happening if I DO modify the object directly ... true.

Thank you all for your critisizm!

> Actually I don't see the value of always keeping in mind that the raw input
> and backed object should have different values until final form submit.

I sort of thought of a situation where the user is browsing paged data
back and forth without committing to the proposed default values. But
in my situation, whenever the user browses, the models are
re-populated from db.

Another situation might be that I have an inline editor and a pop-up
editor and when the user opens the pop-up editor, he might not have
committed to the values. BUT again, opening the pop-up in our case
requires validating-saving-and-repopulating the model. So no problem
here either.

Lesson learned.

**
Martin


OSiV shouldn't be the reason because the object should be detached
> when submitting the form and it should be merged into a brand new hibernate
> session.
>
> Actually I don't see the value of always keeping in mind that the raw input
> and backed object should have different values until final form submit. If
> your reusable components can submit form and aren't aware about that you
> can't reuse them in that sort of form. From my perspective your hack does
> not seem cleaner.
>
> What i'm doing in order to set the default value (for instance today for
> date picker) is subclassing form component and initialize its model object.
> It looks shorter and cleaner.
>
>
> MartinM wrote:
>>
>>> Typically to prefill a form you have the backing model object have
>>> sensible defaults.  i.e., a form that edits a person is given a
>>> person, and the person object has it's gender set to "male" as a
>>> default - that is reflected in your form when it is rendered.
>>
>> The problem is that it is not a NEW object. It is an old object with
>> "proposed new values" which the user must SUBMIT in order to be stored
>> into the object etc.
>>
>>> otherwise, you could call setModelObject or perhaps setValue?
>>
>> Well.. that will destroy the object state, which is a different hassle.
>>
>> **
>> Martin
>>
>>>
>>> --
>>> Jeremy Thomerson
>>> http://www.wickettraining.com
>>>
>>>
>>>
>>>
>>> On Tue, Jul 7, 2009 at 8:57 AM, Martin
>>> Makundi<ma...@koodaripalvelut.com> wrote:
>>>> Hi!
>>>>
>>>> What is the proper way to prefill a wicket form (not poke the model
>>>> before submit!!!)?
>>>>
>>>> I have used a hack:
>>>>
>>>>      Field rawInputField =
>>>> FormComponent.class.getDeclaredField("rawInput");
>>>>      rawInputField.setAccessible(true);
>>>>      rawInputField.set(component, description);
>>>>
>>>> Is there a better way?
>>>>
>>>> **
>>>> Martin
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Prefill-form-not-model--tp24373824p24386875.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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: Prefill form not model?

Posted by Vladimir K <ko...@gmail.com>.
Martin,

having read the thread I didn't get why you can not modify the object
itself. OSiV shouldn't be the reason because the object should be detached
when submitting the form and it should be merged into a brand new hibernate
session.

Actually I don't see the value of always keeping in mind that the raw input
and backed object should have different values until final form submit. If
your reusable components can submit form and aren't aware about that you
can't reuse them in that sort of form. From my perspective your hack does
not seem cleaner.

What i'm doing in order to set the default value (for instance today for
date picker) is subclassing form component and initialize its model object.
It looks shorter and cleaner.


MartinM wrote:
> 
>> Typically to prefill a form you have the backing model object have
>> sensible defaults.  i.e., a form that edits a person is given a
>> person, and the person object has it's gender set to "male" as a
>> default - that is reflected in your form when it is rendered.
> 
> The problem is that it is not a NEW object. It is an old object with
> "proposed new values" which the user must SUBMIT in order to be stored
> into the object etc.
> 
>> otherwise, you could call setModelObject or perhaps setValue?
> 
> Well.. that will destroy the object state, which is a different hassle.
> 
> **
> Martin
> 
>>
>> --
>> Jeremy Thomerson
>> http://www.wickettraining.com
>>
>>
>>
>>
>> On Tue, Jul 7, 2009 at 8:57 AM, Martin
>> Makundi<ma...@koodaripalvelut.com> wrote:
>>> Hi!
>>>
>>> What is the proper way to prefill a wicket form (not poke the model
>>> before submit!!!)?
>>>
>>> I have used a hack:
>>>
>>>      Field rawInputField =
>>> FormComponent.class.getDeclaredField("rawInput");
>>>      rawInputField.setAccessible(true);
>>>      rawInputField.set(component, description);
>>>
>>> Is there a better way?
>>>
>>> **
>>> Martin
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Prefill-form-not-model--tp24373824p24386875.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Prefill form not model?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
> Typically to prefill a form you have the backing model object have
> sensible defaults.  i.e., a form that edits a person is given a
> person, and the person object has it's gender set to "male" as a
> default - that is reflected in your form when it is rendered.

The problem is that it is not a NEW object. It is an old object with
"proposed new values" which the user must SUBMIT in order to be stored
into the object etc.

> otherwise, you could call setModelObject or perhaps setValue?

Well.. that will destroy the object state, which is a different hassle.

**
Martin

>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>
>
>
>
> On Tue, Jul 7, 2009 at 8:57 AM, Martin
> Makundi<ma...@koodaripalvelut.com> wrote:
>> Hi!
>>
>> What is the proper way to prefill a wicket form (not poke the model
>> before submit!!!)?
>>
>> I have used a hack:
>>
>>      Field rawInputField = FormComponent.class.getDeclaredField("rawInput");
>>      rawInputField.setAccessible(true);
>>      rawInputField.set(component, description);
>>
>> Is there a better way?
>>
>> **
>> Martin
>>
>> ---------------------------------------------------------------------
>> 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
>
>

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


Re: Prefill form not model?

Posted by Jeremy Thomerson <je...@wickettraining.com>.
Typically to prefill a form you have the backing model object have
sensible defaults.  i.e., a form that edits a person is given a
person, and the person object has it's gender set to "male" as a
default - that is reflected in your form when it is rendered.

otherwise, you could call setModelObject or perhaps setValue?

--
Jeremy Thomerson
http://www.wickettraining.com




On Tue, Jul 7, 2009 at 8:57 AM, Martin
Makundi<ma...@koodaripalvelut.com> wrote:
> Hi!
>
> What is the proper way to prefill a wicket form (not poke the model
> before submit!!!)?
>
> I have used a hack:
>
>      Field rawInputField = FormComponent.class.getDeclaredField("rawInput");
>      rawInputField.setAccessible(true);
>      rawInputField.set(component, description);
>
> Is there a better way?
>
> **
> Martin
>
> ---------------------------------------------------------------------
> 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: Prefill form not model?

Posted by Igor Vaynberg <ig...@gmail.com>.
write a model that returns your default value in getobject and updates
the object in setobject

-igor

On Tue, Jul 7, 2009 at 6:57 AM, Martin
Makundi<ma...@koodaripalvelut.com> wrote:
> Hi!
>
> What is the proper way to prefill a wicket form (not poke the model
> before submit!!!)?
>
> I have used a hack:
>
>      Field rawInputField = FormComponent.class.getDeclaredField("rawInput");
>      rawInputField.setAccessible(true);
>      rawInputField.set(component, description);
>
> Is there a better way?
>
> **
> Martin
>
> ---------------------------------------------------------------------
> 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