You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by David Leangen <wi...@leangen.net> on 2009/08/05 12:20:26 UTC
How do I update my model?
Hello!
I have a form in a panel like so:
public class MyPanel extends Panel
{
Object someModelObject;
public MyPanel( ... )
{
setModel( new Model( Object ) );
....
add( new MyForm( ... ) );
}
private static MyForm extends Form
{
private final MyPanel panel;
MyForm( ... )
{
add( new TextField( "text", new PropertyModel( panel,
"someModelObject" );
add( new MyDropDownChoice( "dropdown" ..., new
PropertyModel( panel, "someModelObject" );
}
}
}
I have MyDropDownChoice set to capture onChange, and in
onSelectionChanged I update the model object.
Problem is that the field is not getting updated upon refresh, even if
the model object is being changed (yes, the model is indeed changed,
and yes, they all refer to the same model).
Do I need to mark the model object as dirty or something for the other
components to refresh?
BTW, in onSelectionChanged, I tried:
panel.modelChanged();
but that didn't help much.
Thanks!
=David
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How do I update my model?
Posted by nino martinez wael <ni...@gmail.com>.
an example where I replace panels instead of updating:
dropDownExercise = new DropDownChoice("exercise", new Model(),
new PropertyModel(selectedCategory, "exercises"),
new HasNameRender()) {
@Override
protected boolean wantOnSelectionChangedNotifications() {
return true;
}
@Override
protected void onSelectionChanged(Object newSelection) {
super.onSelectionChanged(newSelection);
selectedExercise.setObject(newSelection);
Panel panel = new ExercisePanel(EXERCISE_PANEL_ID,
selectedExercise);
exercisePanel.replaceWith(panel);
exercisePanel = panel;
}
};
2009/8/5 nino martinez wael <ni...@gmail.com>:
> hmm what I have is this:
>
> @Override
> protected void onSelectionChanged(Object newSelection) {
> // TODO Auto-generated method stub
> super.onSelectionChanged(newSelection);
> selectedCategoryNameTranslatable.modelChanged();
> dropDownExercise.setModelObject(null);
> dropDownExercise.setChoices(((ExerciseCategory) newSelection)
> .getExercises());
> dropDownExercise.setVisible(true);
> }
>
> it's from an old 1.3 project... So seems similar to what you do..
>
> 2009/8/5 David Leangen <wi...@leangen.net>:
>>
>> Hello!
>>
>> I have a form in a panel like so:
>>
>> public class MyPanel extends Panel
>> {
>> Object someModelObject;
>>
>> public MyPanel( ... )
>> {
>> setModel( new Model( Object ) );
>> ....
>>
>> add( new MyForm( ... ) );
>> }
>>
>> private static MyForm extends Form
>> {
>> private final MyPanel panel;
>>
>> MyForm( ... )
>> {
>> add( new TextField( "text", new PropertyModel( panel,
>> "someModelObject" );
>>
>> add( new MyDropDownChoice( "dropdown" ..., new PropertyModel(
>> panel, "someModelObject" );
>> }
>> }
>>
>> }
>>
>>
>>
>> I have MyDropDownChoice set to capture onChange, and in onSelectionChanged I
>> update the model object.
>>
>> Problem is that the field is not getting updated upon refresh, even if the
>> model object is being changed (yes, the model is indeed changed, and yes,
>> they all refer to the same model).
>>
>> Do I need to mark the model object as dirty or something for the other
>> components to refresh?
>>
>> BTW, in onSelectionChanged, I tried:
>>
>> panel.modelChanged();
>>
>> but that didn't help much.
>>
>>
>> Thanks!
>> =David
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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 do I update my model?
Posted by nino martinez wael <ni...@gmail.com>.
hmm what I have is this:
@Override
protected void onSelectionChanged(Object newSelection) {
// TODO Auto-generated method stub
super.onSelectionChanged(newSelection);
selectedCategoryNameTranslatable.modelChanged();
dropDownExercise.setModelObject(null);
dropDownExercise.setChoices(((ExerciseCategory) newSelection)
.getExercises());
dropDownExercise.setVisible(true);
}
it's from an old 1.3 project... So seems similar to what you do..
2009/8/5 David Leangen <wi...@leangen.net>:
>
> Hello!
>
> I have a form in a panel like so:
>
> public class MyPanel extends Panel
> {
> Object someModelObject;
>
> public MyPanel( ... )
> {
> setModel( new Model( Object ) );
> ....
>
> add( new MyForm( ... ) );
> }
>
> private static MyForm extends Form
> {
> private final MyPanel panel;
>
> MyForm( ... )
> {
> add( new TextField( "text", new PropertyModel( panel,
> "someModelObject" );
>
> add( new MyDropDownChoice( "dropdown" ..., new PropertyModel(
> panel, "someModelObject" );
> }
> }
>
> }
>
>
>
> I have MyDropDownChoice set to capture onChange, and in onSelectionChanged I
> update the model object.
>
> Problem is that the field is not getting updated upon refresh, even if the
> model object is being changed (yes, the model is indeed changed, and yes,
> they all refer to the same model).
>
> Do I need to mark the model object as dirty or something for the other
> components to refresh?
>
> BTW, in onSelectionChanged, I tried:
>
> panel.modelChanged();
>
> but that didn't help much.
>
>
> Thanks!
> =David
>
>
>
>
> ---------------------------------------------------------------------
> 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 do I update my model?
Posted by David Leangen <wi...@leangen.net>.
Ok, thanks for the tip.
Looks like all I needed was to call modelChanged() directly on the
TextField.
Cheers,
=David
On Aug 5, 2009, at 10:21 PM, Craig McIlwee wrote:
> If a FormComponent has raw input (FormComponent.hasRawInput() ==
> true) then it will use that value when rendering instead of its
> model object. I find that pretty often (or more likely always) have
> to call FormComponent.clearInput() when updating a component's model
> object during an ajax request so that it uses the model object
> instead of the raw input. Too bad this isn't clearly documented in
> the FormComponent javadocs, or anywhere else that I can remember,
> instead I had to find this out the hard way by stepping through the
> wicket code.
>
> Craig
>
> -----Original Message-----
> From: David Leangen [mailto:wicket@leangen.net]
> Sent: Wednesday, August 05, 2009 6:20 AM
> To: users@wicket.apache.org
> Subject: How do I update my model?
>
>
> Hello!
>
> I have a form in a panel like so:
>
> public class MyPanel extends Panel
> {
> Object someModelObject;
>
> public MyPanel( ... )
> {
> setModel( new Model( Object ) );
> ....
>
> add( new MyForm( ... ) );
> }
>
> private static MyForm extends Form
> {
> private final MyPanel panel;
>
> MyForm( ... )
> {
> add( new TextField( "text", new PropertyModel( panel,
> "someModelObject" );
>
> add( new MyDropDownChoice( "dropdown" ..., new
> PropertyModel( panel, "someModelObject" );
> }
> }
>
> }
>
>
>
> I have MyDropDownChoice set to capture onChange, and in
> onSelectionChanged I update the model object.
>
> Problem is that the field is not getting updated upon refresh, even if
> the model object is being changed (yes, the model is indeed changed,
> and yes, they all refer to the same model).
>
> Do I need to mark the model object as dirty or something for the other
> components to refresh?
>
> BTW, in onSelectionChanged, I tried:
>
> panel.modelChanged();
>
> but that didn't help much.
>
>
> Thanks!
> =David
>
>
>
>
> ---------------------------------------------------------------------
> 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: How do I update my model?
Posted by Craig McIlwee <cr...@openroadsconsulting.com>.
If a FormComponent has raw input (FormComponent.hasRawInput() == true) then it will use that value when rendering instead of its model object. I find that pretty often (or more likely always) have to call FormComponent.clearInput() when updating a component's model object during an ajax request so that it uses the model object instead of the raw input. Too bad this isn't clearly documented in the FormComponent javadocs, or anywhere else that I can remember, instead I had to find this out the hard way by stepping through the wicket code.
Craig
-----Original Message-----
From: David Leangen [mailto:wicket@leangen.net]
Sent: Wednesday, August 05, 2009 6:20 AM
To: users@wicket.apache.org
Subject: How do I update my model?
Hello!
I have a form in a panel like so:
public class MyPanel extends Panel
{
Object someModelObject;
public MyPanel( ... )
{
setModel( new Model( Object ) );
....
add( new MyForm( ... ) );
}
private static MyForm extends Form
{
private final MyPanel panel;
MyForm( ... )
{
add( new TextField( "text", new PropertyModel( panel,
"someModelObject" );
add( new MyDropDownChoice( "dropdown" ..., new
PropertyModel( panel, "someModelObject" );
}
}
}
I have MyDropDownChoice set to capture onChange, and in
onSelectionChanged I update the model object.
Problem is that the field is not getting updated upon refresh, even if
the model object is being changed (yes, the model is indeed changed,
and yes, they all refer to the same model).
Do I need to mark the model object as dirty or something for the other
components to refresh?
BTW, in onSelectionChanged, I tried:
panel.modelChanged();
but that didn't help much.
Thanks!
=David
---------------------------------------------------------------------
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