You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by armandoxxx <ar...@dropchop.com> on 2010/10/04 14:01:41 UTC
Form with dynamic fields model not updating
Hi ppl
Got a little problem with my form with dynamic fields.
My form fields are panels added to ListView. Each panel representing a field
has sub components (for label, text field etc).
The problem I'm having is how to access these list view items, so I can set
them default model
I would like to do this on my form
class MyForm {
private ListView<Component> formFieldList;
@Override
protected void onModelChanged() {
Object obj = this.getDefaultModelObject();
if (obj instanceof Translation) {
for (Component cmp :
(List<Component>)this.formFieldList.getDefaultModelObject()) {
cmp.setDefaultModelObject(obj);
}
}
}
}
this code is not working now, so my guess is that this is not the proper way
to itterate list items and set them proper model object.
Kind regards
Armando
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Form-with-dynamic-fields-model-not-updating-tp2954185p2954185.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: Form with dynamic fields model not updating
Posted by armandoxxx <ar...@dropchop.com>.
Here's the working code in my form class:
@Override
protected void onModelChanged() {
super.onModelChanged();
if (this.formFieldList == null) return;
this.formFieldList.visitChildren(new
FieldVisitor<Component>((IModel<T>)this.getDefaultModel()));
}
Code in visitor:
public class FieldVisitor<T extends Component> implements IVisitor<T> {
private static final Logger LOG =
LoggerFactory.getLogger(FieldVisitor.class);
private IModel<?> model;
public FieldVisitor(final IModel<?> theModel) {
this.model = theModel;
}
@Override
public Object component(final Component theComponent) {
((Component)theComponent.getDefaultModelObject()).setDefaultModelObject(this.model.getObject());
((Component)theComponent.getDefaultModelObject()).modelChanged(); //I
GUESS THIS ONE WAS MISSING
return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
}
}
Regards
Armando
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Form-with-dynamic-fields-model-not-updating-tp2954185p2955673.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: Form with dynamic fields model not updating
Posted by armandoxxx <ar...@dropchop.com>.
Hey mate
Thank you for your super fast reply;)
Here's my code:
this.formFieldList.visitChildren(new IVisitor<Component>() {
@Override
public Object component(final Component theComponent) {
ListItem<Component> item = (ListItem<Component>)theComponent;
((Component)item.getDefaultModelObject()).setDefaultModelObject(TranslationForm.this.getDefaultModelObject());
return item;
}
});
but method onModelChanged on my custom components still don't get called.
searching further for solution ...
thank you !
Armando
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Form-with-dynamic-fields-model-not-updating-tp2954185p2954376.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: Form with dynamic fields model not updating
Posted by Jeremy Thomerson <je...@wickettraining.com>.
You could use visitChildren
Jeremy Thomerson
http://wickettraining.com
-- sent from my "smart" phone, so please excuse spelling, formatting, or
compiler errors
On Oct 4, 2010 7:02 AM, "armandoxxx" <ar...@dropchop.com> wrote:
Hi ppl
Got a little problem with my form with dynamic fields.
My form fields are panels added to ListView. Each panel representing a field
has sub components (for label, text field etc).
The problem I'm having is how to access these list view items, so I can set
them default model
I would like to do this on my form
class MyForm {
private ListView<Component> formFieldList;
@Override
protected void onModelChanged() {
Object obj = this.getDefaultModelObject();
if (obj instanceof Translation) {
for (Component cmp :
(List<Component>)this.formFieldList.getDefaultModelObject()) {
cmp.setDefaultModelObject(obj);
}
}
}
}
this code is not working now, so my guess is that this is not the proper way
to itterate list items and set them proper model object.
Kind regards
Armando
--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Form-with-dynamic-fields-model-not-updating-tp2954185p2954185.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