You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Troy Cauble <tr...@gmail.com> on 2010/11/04 04:34:04 UTC

generated form and form IDs vs model confusion

Typically, one sets a FormComponent's ID to match the data model.
My form is generated from data, so the IDs are a recursive set of "fieldFrag",
"list", "blockFrag", "label", "value" and RepeatingView#newChildID().

My data on the other hand is represented by HashMap<String,String>
and CompoundPropertyModel.  The keys are generated.

This works fine when my form has a Model before I construct it.
Where each FormComponent is constructed I do this.

           new PropertyModel<String>(getDefaultModel(), key);

Anyway, PM doesn't like it when the first arg is null.  So I can't support
using setDefaultModel() after the form components are instantiated.

How can I support setDefaultModel() ?  ComponentPropertyModel looks
like it might work if it wasn't read only.

Thanks,
-troy

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


Re: generated form and form IDs vs model confusion

Posted by Alexander Morozov <al...@gmail.com>.
I have the similar issue with Form (with CompountPropertyModel attached) and
several text fields which generated on-the-fly by RepeatingView with no
model specified (only field ID). I didn't investigate the issue deeply yet,
but thinks the problem within model inheritance that "breaks" by presence of
RepeatingView in the hierarchy.

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/generated-form-and-form-IDs-vs-model-confusion-tp3026506p3029157.html
Sent from the Users forum 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: generated form and form IDs vs model confusion

Posted by Troy Cauble <tr...@gmail.com>.
On Thu, Nov 4, 2010 at 12:25 AM, Jeremy Thomerson
<je...@wickettraining.com> wrote:
> On Wed, Nov 3, 2010 at 10:34 PM, Troy Cauble <tr...@gmail.com> wrote:
>
>> Typically, one sets a FormComponent's ID to match the data model.
>> My form is generated from data, so the IDs are a recursive set of
>> "fieldFrag",
>> "list", "blockFrag", "label", "value" and RepeatingView#newChildID().
>>
>> My data on the other hand is represented by HashMap<String,String>
>> and CompoundPropertyModel.  The keys are generated.
>>
>> This works fine when my form has a Model before I construct it.
>> Where each FormComponent is constructed I do this.
>>
>>           new PropertyModel<String>(getDefaultModel(), key);
>>
>> Anyway, PM doesn't like it when the first arg is null.  So I can't support
>> using setDefaultModel() after the form components are instantiated.
>>
>> How can I support setDefaultModel() ?  ComponentPropertyModel looks
>> like it might work if it wasn't read only.
>>
>> Thanks,
>> -troy
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> If your form is using a compoundpropertymodel, your form components don't
> need an explicit property model.

....

> TextField("someKeyThatRepresentsAPropertyOnTheThingReturnedByAboveModel"));


My issue is that "someKeyThatRepresentsAPropertyOnTheThing..."
is also "theIdThatMatchesInTheHtml".

But my form is generated on-the-fly from external data.  So the HTML
IDs are always "value"
or "label".  There are many "value" and "label" ids in my generated forms.

Here's a more concise summary of my problem:

I'm trying to leverage a CompoundPropertyModel, but since my form is
generated on-the-fly,
a FormComponent's ID to match the HTML cannot be the ID to match the DATA.

How can I effectively have these IDs be different?  This works

         new PropertyModel<String>(getDefaultModel(), dataKey);

but only if the model is set before this is called.
Otherwise t throws an exception.  Also, I assume a later switch by
Form#setModel()
would fail because we're already bound to the original.  I want the late binding
that (I think) a standard FormComponent "id" string gets.

ComponentPropertyModel looks like it might work if it wasn't read only.
Do I need to write something like ComponentPM?

Thanks!
-troy

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


Re: generated form and form IDs vs model confusion

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Wed, Nov 3, 2010 at 10:34 PM, Troy Cauble <tr...@gmail.com> wrote:

> Typically, one sets a FormComponent's ID to match the data model.
> My form is generated from data, so the IDs are a recursive set of
> "fieldFrag",
> "list", "blockFrag", "label", "value" and RepeatingView#newChildID().
>
> My data on the other hand is represented by HashMap<String,String>
> and CompoundPropertyModel.  The keys are generated.
>
> This works fine when my form has a Model before I construct it.
> Where each FormComponent is constructed I do this.
>
>           new PropertyModel<String>(getDefaultModel(), key);
>
> Anyway, PM doesn't like it when the first arg is null.  So I can't support
> using setDefaultModel() after the form components are instantiated.
>
> How can I support setDefaultModel() ?  ComponentPropertyModel looks
> like it might work if it wasn't read only.
>
> Thanks,
> -troy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
If your form is using a compoundpropertymodel, your form components don't
need an explicit property model.

class YourForm extends Form {
setModel(IModel model) {
// ensure that you always get a compoundpropertymodel:
super.setModel(new CompoundPropertyModel(model));
}
}

Form form = new YourForm();
form.setModel(new LoadableDetachableFooBarSomethingOrOtherModel());

form.add(new
TextField("someKeyThatRepresentsAPropertyOnTheThingReturnedByAboveModel"));

That should work.

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*