wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ondrej Zizka <ozi...@redhat.com>
Subject Re: How to pass model changes to parent components? onModelChanged() not working
Date Tue, 22 Jan 2013 04:49:04 GMT
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 <ozizka@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<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


Mime
View raw message