You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ondrej Zizka <oz...@redhat.com> on 2013/01/21 18:30:35 UTC

How to pass model changes to parent components? onModelChanged() not working

Hi all,

I have a component containing a form with many TextFields.
The way it should work is that when changed, the value should be 
persisted immediately (no Save button, all through AJAX).

The AJAX calls work fine, the value gets to the model.

The code to save the model (and the entity contained) is in the parent 
component.
I thought I would override onModelChanged() to propagate the changes 
from the components to the parent.
But onModelChanged() is not called.

Parent has its own model as class member field.
The subcomponents use this:

     ReleaseTraitRowPanel( String id, IModel<IHasTraits> relModel, ... ) {
         ...
         PropertyModel<String> traitModel = new PropertyModel( 
relModel.getObject().getTraits(), prop);

         EditableLink4 link = new EditableLink4("link", traitModel){
             // Pass the change notification to upper level. TODO: Does 
Wicket do this automatically?
             @Override protected void onModelChanged() {
                 ReleaseTraitRowPanel.this.onModelChanged();
             }
         };
         ...

     }

How should it be done?
Should I pass the onModelChanged() at all? Or does wicket have some way 
to notify the other model of changes?

Related - is CompoundPropertyModel only for forms, or can I use it with 
any component? I could use it here - `prop` is the same as id.

Thanks,
Ondra

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


Removing items from ListView in AJAX request // Re: How to pass model changes to parent components? onModelChanged() not working

Posted by Ondrej Zizka <oz...@redhat.com>.
Ok, I got it.
Seems I have to manually refresh the ListView's model. So now it's like 
below.

I thought it would re-load it between
  * onDelete(), which is triggered in 
AjaxEventBehavior("onclick")#onEvent(),
  * and ListView rendering.

Could someone enlight me pls.

Thanks,
Ondra

         ListView<ProductCustomField> listView;
         add( listView = new ListView<ProductCustomField>("fieldsRows", 
listModel){
             @Override
             protected void populateItem( final 
ListItem<ProductCustomField> item ) {
                 final ListView thatLV = this;
                 item.add( new CustomFieldRowPanel("fieldRow", 
item.getModel()){
                     // Delete icon was clicked.
                     @Override
                     protected void onDelete( String name, 
AjaxRequestTarget target ) {
                         Map<String,ProductCustomField> fieldsMap = 
(Map) CustomFieldsPanel.this.getDefaultModelObject();
                         //fieldsMap.remove( 
item.getModelObject().getName() ); // ListView uses indexes -> leads to 
bad offsets!
                         fieldsMap.remove( name );  // This is more 
robust. But still, this renders the list before removal...?
                         item.remove();
                         thatLV.getDefaultModel().detach();
                         thatLV.getDefaultModel().getObject();
                         thatLV.modelChanged();
                         target.add( CustomFieldsPanel.this ); // Update UI.
                         try {
                             CustomFieldsPanel.this.onChange( target ); 
// Persists.
                         } catch (Exception ex){
                             feedbackPanel.error( ex.toString() );
                         }
                     }
                 });
             }
         });



On 01/22/2013 05:54 AM, Ondrej Zizka wrote:
> Forgot to write: My problem is that the Map item is deleted, but 
> Wicket renders the given sub-component with the old Map for some reason.
> But on next Ajax request, it already uses the new one.
> I'm a bit puzzled.
>
>
> On 01/22/2013 05:49 AM, Ondrej Zizka wrote:
>> On 01/21/2013 10:52 PM, Martin Grigorov wrote:
>>> Hi,
>>>
>>> Wicket updates the model with the new value. If this model is shared
>>> between several components then all of them have the new value for 
>>> free. No
>>> need to notify them.
>>> If you still need to notify then you can use #updateModel() method -
>>> org.apache.wicket.markup.html.form.FormComponent#updateModel.
>> I need to notify when I change the object (model stays the same) in 
>> this way:
>>
>>     private void onProductUpdate( AjaxRequestTarget target ) {
>>         if( target != null )  target.add( this.feedbackPanel );
>>         try {
>>             product = productDao.update( product );
>>             modelChanged();
>>             this.info("Product saved.");
>>             if( target != null )
>> target.appendJavaScript("window.notifyFlash('Product saved.')");
>>         } catch( Exception ex ){
>>             this.feedbackPanel.info("Saving product failed: " + 
>> ex.toString());
>>         }
>>     }
>>
>> So I basically need to tell Wicket that this and that needs to 
>> re-render.
>> Maybe I do the mistake of thinking "Wicket works like Swing which 
>> basically works like MFC based on Win32 API", so perhaps I should 
>> forget the idea of "invalidating" the model?
>> Or is updateModel() the way to go here?
>>
>> Thanks,
>> Ondra
>>
>>>
>>> CompoundPropertyModel is meant for components which have children. Such
>>> component may have a compound model and all its children can update the
>>> value in the respective branch of this model.
>>>
>>>
>>> On Mon, Jan 21, 2013 at 7:30 PM, Ondrej Zizka <oz...@redhat.com> 
>>> wrote:
>>>
>>>> Hi all,
>>>>
>>>> I have a component containing a form with many TextFields.
>>>> The way it should work is that when changed, the value should be 
>>>> persisted
>>>> immediately (no Save button, all through AJAX).
>>>>
>>>> The AJAX calls work fine, the value gets to the model.
>>>>
>>>> The code to save the model (and the entity contained) is in the parent
>>>> component.
>>>> I thought I would override onModelChanged() to propagate the 
>>>> changes from
>>>> the components to the parent.
>>>> But onModelChanged() is not called.
>>>>
>>>> Parent has its own model as class member field.
>>>> The subcomponents use this:
>>>>
>>>>      ReleaseTraitRowPanel( String id, IModel<IHasTraits> relModel, 
>>>> ... ) {
>>>>          ...
>>>>          PropertyModel<String> traitModel = new PropertyModel(
>>>> relModel.getObject().**getTraits(), prop);
>>>>
>>>>          EditableLink4 link = new EditableLink4("link", traitModel){
>>>>              // Pass the change notification to upper level. TODO: 
>>>> Does
>>>> Wicket do this automatically?
>>>>              @Override protected void onModelChanged() {
>>>> ReleaseTraitRowPanel.this.**onModelChanged();
>>>>              }
>>>>          };
>>>>          ...
>>>>
>>>>      }
>>>>
>>>> How should it be done?
>>>> Should I pass the onModelChanged() at all? Or does wicket have some 
>>>> way to
>>>> notify the other model of changes?
>>>>
>>>> Related - is CompoundPropertyModel only for forms, or can I use it 
>>>> with
>>>> any component? I could use it here - `prop` is the same as id.
>>>>
>>>> Thanks,
>>>> Ondra
>>>>
>>>> ------------------------------**------------------------------**--------- 
>>>>
>>>> To unsubscribe, e-mail: 
>>>> users-unsubscribe@wicket.**apache.org<us...@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
>


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


Re: How to pass model changes to parent components? onModelChanged() not working

Posted by Ondrej Zizka <oz...@redhat.com>.
Solved. For future reference:

It was actually LoadableDetachableModel causing this.
At least after I switched to AbstractReadOnlyModel whose getModel() 
called Map#values(), everything works fine.

I didn't investigate why LDM was behaving as described, but probably 
because it load()ed once per request, at the begining, and after my 
change to Map, it used this stale data.

Ondra


On 01/22/2013 05:59 PM, Paul Bors wrote:
> You should use a LoadableDetachableModel and wrap it around a
> CompondPropertyModel or whatever other type of model you're using.
>
> In this way the object will be refreshed on each "render" with the values
> from the databse.
>
> Btw, why exactly are you using a map for?
> Did you develop your own compound form componet in order to implement and
> work with FormComponent#**updateModel?
>
> ~ Thank you,
>     Paul Bors
> On Mon, Jan 21, 2013 at 11:54 PM, Ondrej Zizka <oz...@redhat.com> wrote:
>
>> Forgot to write: My problem is that the Map item is deleted, but Wicket
>> renders the given sub-component with the old Map for some reason.
>> But on next Ajax request, it already uses the new one.
>> I'm a bit puzzled.
>>
>>
>>
>> On 01/22/2013 05:49 AM, Ondrej Zizka wrote:
>>
>>> On 01/21/2013 10:52 PM, Martin Grigorov wrote:
>>>
>>>> Hi,
>>>>
>>>> Wicket updates the model with the new value. If this model is shared
>>>> between several components then all of them have the new value for free.
>>>> No
>>>> need to notify them.
>>>> If you still need to notify then you can use #updateModel() method -
>>>> org.apache.wicket.markup.html.**form.FormComponent#**updateModel.
>>>>
>>> I need to notify when I change the object (model stays the same) in this
>>> way:
>>>
>>>      private void onProductUpdate( AjaxRequestTarget target ) {
>>>          if( target != null )  target.add( this.feedbackPanel );
>>>          try {
>>>              product = productDao.update( product );
>>>              modelChanged();
>>>              this.info("Product saved.");
>>>              if( target != null )
>>> target.appendJavaScript("**window.notifyFlash('Product saved.')");
>>>          } catch( Exception ex ){
>>>              this.feedbackPanel.info("**Saving product failed: " +
>>> ex.toString());
>>>          }
>>>      }
>>>
>>> So I basically need to tell Wicket that this and that needs to re-render.
>>> Maybe I do the mistake of thinking "Wicket works like Swing which
>>> basically works like MFC based on Win32 API", so perhaps I should forget
>>> the idea of "invalidating" the model?
>>> Or is updateModel() the way to go here?
>>>
>>> Thanks,
>>> Ondra
>>>
>>>
>>>> CompoundPropertyModel is meant for components which have children. Such
>>>> component may have a compound model and all its children can update the
>>>> value in the respective branch of this model.
>>>>
>>>>
>>>> On Mon, Jan 21, 2013 at 7:30 PM, Ondrej Zizka <oz...@redhat.com> wrote:
>>>>
>>>>   Hi all,
>>>>> I have a component containing a form with many TextFields.
>>>>> The way it should work is that when changed, the value should be
>>>>> persisted
>>>>> immediately (no Save button, all through AJAX).
>>>>>
>>>>> The AJAX calls work fine, the value gets to the model.
>>>>>
>>>>> The code to save the model (and the entity contained) is in the parent
>>>>> component.
>>>>> I thought I would override onModelChanged() to propagate the changes
>>>>> from
>>>>> the components to the parent.
>>>>> But onModelChanged() is not called.
>>>>>
>>>>> Parent has its own model as class member field.
>>>>> The subcomponents use this:
>>>>>
>>>>>       ReleaseTraitRowPanel( String id, IModel<IHasTraits> relModel, ...
>>>>> ) {
>>>>>           ...
>>>>>           PropertyModel<String> traitModel = new PropertyModel(
>>>>> relModel.getObject().****getTraits(), prop);
>>>>>
>>>>>           EditableLink4 link = new EditableLink4("link", traitModel){
>>>>>               // Pass the change notification to upper level. TODO: Does
>>>>> Wicket do this automatically?
>>>>>               @Override protected void onModelChanged() {
>>>>>                   ReleaseTraitRowPanel.this.****onModelChanged();
>>>>>               }
>>>>>           };
>>>>>           ...
>>>>>
>>>>>       }
>>>>>
>>>>> How should it be done?
>>>>> Should I pass the onModelChanged() at all? Or does wicket have some way
>>>>> to
>>>>> notify the other model of changes?
>>>>>
>>>>> Related - is CompoundPropertyModel only for forms, or can I use it with
>>>>> any component? I could use it here - `prop` is the same as id.
>>>>>
>>>>> Thanks,
>>>>> Ondra
>>>>>
>>>>> ------------------------------****----------------------------**--**---------
>>>>>
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apa**che.org<http://apache.org>
>>>>> <us...@wicket.apache.org>
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>>
>>> ------------------------------**------------------------------**---------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@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 pass model changes to parent components? onModelChanged() not working

Posted by Paul Bors <pa...@bors.ws>.
You should use a LoadableDetachableModel and wrap it around a
CompondPropertyModel or whatever other type of model you're using.

In this way the object will be refreshed on each "render" with the values
from the databse.

Btw, why exactly are you using a map for?
Did you develop your own compound form componet in order to implement and
work with FormComponent#**updateModel?

~ Thank you,
   Paul Bors
On Mon, Jan 21, 2013 at 11:54 PM, Ondrej Zizka <oz...@redhat.com> wrote:

> Forgot to write: My problem is that the Map item is deleted, but Wicket
> renders the given sub-component with the old Map for some reason.
> But on next Ajax request, it already uses the new one.
> I'm a bit puzzled.
>
>
>
> On 01/22/2013 05:49 AM, Ondrej Zizka wrote:
>
>> On 01/21/2013 10:52 PM, Martin Grigorov wrote:
>>
>>> Hi,
>>>
>>> Wicket updates the model with the new value. If this model is shared
>>> between several components then all of them have the new value for free.
>>> No
>>> need to notify them.
>>> If you still need to notify then you can use #updateModel() method -
>>> org.apache.wicket.markup.html.**form.FormComponent#**updateModel.
>>>
>> I need to notify when I change the object (model stays the same) in this
>> way:
>>
>>     private void onProductUpdate( AjaxRequestTarget target ) {
>>         if( target != null )  target.add( this.feedbackPanel );
>>         try {
>>             product = productDao.update( product );
>>             modelChanged();
>>             this.info("Product saved.");
>>             if( target != null )
>> target.appendJavaScript("**window.notifyFlash('Product saved.')");
>>         } catch( Exception ex ){
>>             this.feedbackPanel.info("**Saving product failed: " +
>> ex.toString());
>>         }
>>     }
>>
>> So I basically need to tell Wicket that this and that needs to re-render.
>> Maybe I do the mistake of thinking "Wicket works like Swing which
>> basically works like MFC based on Win32 API", so perhaps I should forget
>> the idea of "invalidating" the model?
>> Or is updateModel() the way to go here?
>>
>> Thanks,
>> Ondra
>>
>>
>>> CompoundPropertyModel is meant for components which have children. Such
>>> component may have a compound model and all its children can update the
>>> value in the respective branch of this model.
>>>
>>>
>>> On Mon, Jan 21, 2013 at 7:30 PM, Ondrej Zizka <oz...@redhat.com> wrote:
>>>
>>>  Hi all,
>>>>
>>>> I have a component containing a form with many TextFields.
>>>> The way it should work is that when changed, the value should be
>>>> persisted
>>>> immediately (no Save button, all through AJAX).
>>>>
>>>> The AJAX calls work fine, the value gets to the model.
>>>>
>>>> The code to save the model (and the entity contained) is in the parent
>>>> component.
>>>> I thought I would override onModelChanged() to propagate the changes
>>>> from
>>>> the components to the parent.
>>>> But onModelChanged() is not called.
>>>>
>>>> Parent has its own model as class member field.
>>>> The subcomponents use this:
>>>>
>>>>      ReleaseTraitRowPanel( String id, IModel<IHasTraits> relModel, ...
>>>> ) {
>>>>          ...
>>>>          PropertyModel<String> traitModel = new PropertyModel(
>>>> relModel.getObject().****getTraits(), prop);
>>>>
>>>>          EditableLink4 link = new EditableLink4("link", traitModel){
>>>>              // Pass the change notification to upper level. TODO: Does
>>>> Wicket do this automatically?
>>>>              @Override protected void onModelChanged() {
>>>>                  ReleaseTraitRowPanel.this.****onModelChanged();
>>>>              }
>>>>          };
>>>>          ...
>>>>
>>>>      }
>>>>
>>>> How should it be done?
>>>> Should I pass the onModelChanged() at all? Or does wicket have some way
>>>> to
>>>> notify the other model of changes?
>>>>
>>>> Related - is CompoundPropertyModel only for forms, or can I use it with
>>>> any component? I could use it here - `prop` is the same as id.
>>>>
>>>> Thanks,
>>>> Ondra
>>>>
>>>> ------------------------------****----------------------------**--**---------
>>>>
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apa**che.org<http://apache.org>
>>>> <us...@wicket.apache.org>
>>>> >
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to pass model changes to parent components? onModelChanged() not working

Posted by Ondrej Zizka <oz...@redhat.com>.
Forgot to write: My problem is that the Map item is deleted, but Wicket 
renders the given sub-component with the old Map for some reason.
But on next Ajax request, it already uses the new one.
I'm a bit puzzled.


On 01/22/2013 05:49 AM, Ondrej Zizka wrote:
> On 01/21/2013 10:52 PM, Martin Grigorov wrote:
>> Hi,
>>
>> Wicket updates the model with the new value. If this model is shared
>> between several components then all of them have the new value for 
>> free. No
>> need to notify them.
>> If you still need to notify then you can use #updateModel() method -
>> org.apache.wicket.markup.html.form.FormComponent#updateModel.
> I need to notify when I change the object (model stays the same) in 
> this way:
>
>     private void onProductUpdate( AjaxRequestTarget target ) {
>         if( target != null )  target.add( this.feedbackPanel );
>         try {
>             product = productDao.update( product );
>             modelChanged();
>             this.info("Product saved.");
>             if( target != null )
> target.appendJavaScript("window.notifyFlash('Product saved.')");
>         } catch( Exception ex ){
>             this.feedbackPanel.info("Saving product failed: " + 
> ex.toString());
>         }
>     }
>
> So I basically need to tell Wicket that this and that needs to re-render.
> Maybe I do the mistake of thinking "Wicket works like Swing which 
> basically works like MFC based on Win32 API", so perhaps I should 
> forget the idea of "invalidating" the model?
> Or is updateModel() the way to go here?
>
> Thanks,
> Ondra
>
>>
>> CompoundPropertyModel is meant for components which have children. Such
>> component may have a compound model and all its children can update the
>> value in the respective branch of this model.
>>
>>
>> On Mon, Jan 21, 2013 at 7:30 PM, Ondrej Zizka <oz...@redhat.com> wrote:
>>
>>> Hi all,
>>>
>>> I have a component containing a form with many TextFields.
>>> The way it should work is that when changed, the value should be 
>>> persisted
>>> immediately (no Save button, all through AJAX).
>>>
>>> The AJAX calls work fine, the value gets to the model.
>>>
>>> The code to save the model (and the entity contained) is in the parent
>>> component.
>>> I thought I would override onModelChanged() to propagate the changes 
>>> from
>>> the components to the parent.
>>> But onModelChanged() is not called.
>>>
>>> Parent has its own model as class member field.
>>> The subcomponents use this:
>>>
>>>      ReleaseTraitRowPanel( String id, IModel<IHasTraits> relModel, 
>>> ... ) {
>>>          ...
>>>          PropertyModel<String> traitModel = new PropertyModel(
>>> relModel.getObject().**getTraits(), prop);
>>>
>>>          EditableLink4 link = new EditableLink4("link", traitModel){
>>>              // Pass the change notification to upper level. TODO: Does
>>> Wicket do this automatically?
>>>              @Override protected void onModelChanged() {
>>>                  ReleaseTraitRowPanel.this.**onModelChanged();
>>>              }
>>>          };
>>>          ...
>>>
>>>      }
>>>
>>> How should it be done?
>>> Should I pass the onModelChanged() at all? Or does wicket have some 
>>> way to
>>> notify the other model of changes?
>>>
>>> Related - is CompoundPropertyModel only for forms, or can I use it with
>>> any component? I could use it here - `prop` is the same as id.
>>>
>>> Thanks,
>>> Ondra
>>>
>>> ------------------------------**------------------------------**--------- 
>>>
>>> To unsubscribe, e-mail: 
>>> users-unsubscribe@wicket.**apache.org<us...@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 to pass model changes to parent components? onModelChanged() not working

Posted by Ondrej Zizka <oz...@redhat.com>.
On 01/21/2013 10:52 PM, Martin Grigorov wrote:
> Hi,
>
> Wicket updates the model with the new value. If this model is shared
> between several components then all of them have the new value for free. No
> need to notify them.
> If you still need to notify then you can use #updateModel() method -
> org.apache.wicket.markup.html.form.FormComponent#updateModel.
I need to notify when I change the object (model stays the same) in this 
way:

     private void onProductUpdate( AjaxRequestTarget target ) {
         if( target != null )  target.add( this.feedbackPanel );
         try {
             product = productDao.update( product );
             modelChanged();
             this.info("Product saved.");
             if( target != null )
                 target.appendJavaScript("window.notifyFlash('Product 
saved.')");
         } catch( Exception ex ){
             this.feedbackPanel.info("Saving product failed: " + 
ex.toString());
         }
     }

So I basically need to tell Wicket that this and that needs to re-render.
Maybe I do the mistake of thinking "Wicket works like Swing which 
basically works like MFC based on Win32 API", so perhaps I should forget 
the idea of "invalidating" the model?
Or is updateModel() the way to go here?

Thanks,
Ondra

>
> CompoundPropertyModel is meant for components which have children. Such
> component may have a compound model and all its children can update the
> value in the respective branch of this model.
>
>
> On Mon, Jan 21, 2013 at 7:30 PM, Ondrej Zizka <oz...@redhat.com> wrote:
>
>> Hi all,
>>
>> I have a component containing a form with many TextFields.
>> The way it should work is that when changed, the value should be persisted
>> immediately (no Save button, all through AJAX).
>>
>> The AJAX calls work fine, the value gets to the model.
>>
>> The code to save the model (and the entity contained) is in the parent
>> component.
>> I thought I would override onModelChanged() to propagate the changes from
>> the components to the parent.
>> But onModelChanged() is not called.
>>
>> Parent has its own model as class member field.
>> The subcomponents use this:
>>
>>      ReleaseTraitRowPanel( String id, IModel<IHasTraits> relModel, ... ) {
>>          ...
>>          PropertyModel<String> traitModel = new PropertyModel(
>> relModel.getObject().**getTraits(), prop);
>>
>>          EditableLink4 link = new EditableLink4("link", traitModel){
>>              // Pass the change notification to upper level. TODO: Does
>> Wicket do this automatically?
>>              @Override protected void onModelChanged() {
>>                  ReleaseTraitRowPanel.this.**onModelChanged();
>>              }
>>          };
>>          ...
>>
>>      }
>>
>> How should it be done?
>> Should I pass the onModelChanged() at all? Or does wicket have some way to
>> notify the other model of changes?
>>
>> Related - is CompoundPropertyModel only for forms, or can I use it with
>> any component? I could use it here - `prop` is the same as id.
>>
>> Thanks,
>> Ondra
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@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 pass model changes to parent components? onModelChanged() not working

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Wicket updates the model with the new value. If this model is shared
between several components then all of them have the new value for free. No
need to notify them.
If you still need to notify then you can use #updateModel() method -
org.apache.wicket.markup.html.form.FormComponent#updateModel.

CompoundPropertyModel is meant for components which have children. Such
component may have a compound model and all its children can update the
value in the respective branch of this model.


On Mon, Jan 21, 2013 at 7:30 PM, Ondrej Zizka <oz...@redhat.com> wrote:

> Hi all,
>
> I have a component containing a form with many TextFields.
> The way it should work is that when changed, the value should be persisted
> immediately (no Save button, all through AJAX).
>
> The AJAX calls work fine, the value gets to the model.
>
> The code to save the model (and the entity contained) is in the parent
> component.
> I thought I would override onModelChanged() to propagate the changes from
> the components to the parent.
> But onModelChanged() is not called.
>
> Parent has its own model as class member field.
> The subcomponents use this:
>
>     ReleaseTraitRowPanel( String id, IModel<IHasTraits> relModel, ... ) {
>         ...
>         PropertyModel<String> traitModel = new PropertyModel(
> relModel.getObject().**getTraits(), prop);
>
>         EditableLink4 link = new EditableLink4("link", traitModel){
>             // Pass the change notification to upper level. TODO: Does
> Wicket do this automatically?
>             @Override protected void onModelChanged() {
>                 ReleaseTraitRowPanel.this.**onModelChanged();
>             }
>         };
>         ...
>
>     }
>
> How should it be done?
> Should I pass the onModelChanged() at all? Or does wicket have some way to
> notify the other model of changes?
>
> Related - is CompoundPropertyModel only for forms, or can I use it with
> any component? I could use it here - `prop` is the same as id.
>
> Thanks,
> Ondra
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Feedback in AJAX requests //Re: How to pass model changes to parent components? onModelChanged() not working

Posted by Paul Bors <pa...@bors.ws>.
You need to call setOutputMarkupId( true ); on the object you're adding to
the AjaxTarget.

ie: If your Feedback panel has the output markup id set to true (you can
see it in the HTML as <... id="someWicketGeneratedId" ... \> and you add
the parent of that Feedback panel ot the target you will get an error.

~ Thank you,
   Paul Bors
On Mon, Jan 21, 2013 at 4:18 PM, Ondrej Zizka <oz...@redhat.com> wrote:

> Solved - it was wrong validator which never passed, so onModelChanged()
> was never called.
>
> Now I have related problem:
>
> FeedbackPanel shows the error when a form is submitted, but not on AJAX.
> It has setOutputMarkupId( true );
> It is added to AjaxRequestTarget.
>
> What should I check?
>
> Thanks,
> Ondra
>
>
>
>
> On 01/21/2013 06:30 PM, Ondrej Zizka wrote:
>
>> Hi all,
>>
>> I have a component containing a form with many TextFields.
>> The way it should work is that when changed, the value should be
>> persisted immediately (no Save button, all through AJAX).
>>
>> The AJAX calls work fine, the value gets to the model.
>>
>> The code to save the model (and the entity contained) is in the parent
>> component.
>> I thought I would override onModelChanged() to propagate the changes from
>> the components to the parent.
>> But onModelChanged() is not called.
>>
>> Parent has its own model as class member field.
>> The subcomponents use this:
>>
>>     ReleaseTraitRowPanel( String id, IModel<IHasTraits> relModel, ... ) {
>>         ...
>>         PropertyModel<String> traitModel = new PropertyModel(
>> relModel.getObject().**getTraits(), prop);
>>
>>         EditableLink4 link = new EditableLink4("link", traitModel){
>>             // Pass the change notification to upper level. TODO: Does
>> Wicket do this automatically?
>>             @Override protected void onModelChanged() {
>>                 ReleaseTraitRowPanel.this.**onModelChanged();
>>             }
>>         };
>>         ...
>>
>>     }
>>
>> How should it be done?
>> Should I pass the onModelChanged() at all? Or does wicket have some way
>> to notify the other model of changes?
>>
>> Related - is CompoundPropertyModel only for forms, or can I use it with
>> any component? I could use it here - `prop` is the same as id.
>>
>> Thanks,
>> Ondra
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Feedback in AJAX requests //Re: How to pass model changes to parent components? onModelChanged() not working

Posted by Ondrej Zizka <oz...@redhat.com>.
Solved - it was wrong validator which never passed, so onModelChanged() 
was never called.

Now I have related problem:

FeedbackPanel shows the error when a form is submitted, but not on AJAX.
It has setOutputMarkupId( true );
It is added to AjaxRequestTarget.

What should I check?

Thanks,
Ondra




On 01/21/2013 06:30 PM, Ondrej Zizka wrote:
> Hi all,
>
> I have a component containing a form with many TextFields.
> The way it should work is that when changed, the value should be 
> persisted immediately (no Save button, all through AJAX).
>
> The AJAX calls work fine, the value gets to the model.
>
> The code to save the model (and the entity contained) is in the parent 
> component.
> I thought I would override onModelChanged() to propagate the changes 
> from the components to the parent.
> But onModelChanged() is not called.
>
> Parent has its own model as class member field.
> The subcomponents use this:
>
>     ReleaseTraitRowPanel( String id, IModel<IHasTraits> relModel, ... ) {
>         ...
>         PropertyModel<String> traitModel = new PropertyModel( 
> relModel.getObject().getTraits(), prop);
>
>         EditableLink4 link = new EditableLink4("link", traitModel){
>             // Pass the change notification to upper level. TODO: Does 
> Wicket do this automatically?
>             @Override protected void onModelChanged() {
>                 ReleaseTraitRowPanel.this.onModelChanged();
>             }
>         };
>         ...
>
>     }
>
> How should it be done?
> Should I pass the onModelChanged() at all? Or does wicket have some 
> way to notify the other model of changes?
>
> Related - is CompoundPropertyModel only for forms, or can I use it 
> with any component? I could use it here - `prop` is the same as id.
>
> Thanks,
> Ondra
>
> ---------------------------------------------------------------------
> 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