PDA

View Full Version : Reference to an object from another one



stefano
23 Nov 2010, 6:27 AM
Hi,
I have a Windows that contains a GridPanel (with a list of objects) and a FormPanel (with the detaiil).
As usual when you click on an item on grid panel, I show the detail on the form and then the user can change and save the data.

All this is managed in 3 files: one is the main application.js (with the window) and the others two are for the panels (grid.js and form.js)

I would like that when I submit the form, after calling the service to save data, the grid panel is refreshed (there is a method that load informations with a reader from the server).

Which is the correct mode to do this?

Thank you
bye
stefano

Condor
23 Nov 2010, 6:39 AM
The solution is to have your window listen for a submit of the form and update the grid accordingly.

In very large applications you would move this inter-module communcation to a messagebus (a simple Ext.util.Observable instance with custom application-specific events).

stefano
23 Nov 2010, 7:53 AM
Hi Condor,
I read some tutorial about Observable, so I added to initComponent in Window definition the call:


this.addEvents('saveAndRefresh');
this.on('saveAndRefresh', this.saveAndRefreshWindow);

and then I added the following method (that contains only a message for test):


saveAndRefreshWindow:function() {

Ext.Msg.show({
title:'Test'
,msg:'I am in save and refresh'
,modal:true
,icon:Ext.Msg.INFO
,buttons:Ext.Msg.OK
});

// ...

}


But now what I didn't understand is how to set the window to listen for the form submit?

Thank you
bye
stefano

Condor
23 Nov 2010, 8:08 AM
'this' is your form?

In your window you would do something like:

initComponent: function(){
...
this.form = new MyFormPanel({
listeners: {
saveAndRefresh: doSaveAndRefresh,
scope: this
}
});
...
},
doSaveAndRefresh: function(){
this.grid.getStore().reload(); // or something else
}

stefano
23 Nov 2010, 9:36 AM
Now the event mechanism is working, but I have still a questions to understand how it works: in your code you add the listener to the form, shouldn't it be on the Window object? If I understood well, the event should be managed by the Window.
Thank you for your help