views:

2743

answers:

6

Hi, i've created a Form Panel, and i'm rendering couple of Combo Boxes in the panel with a store which is populated via an response handler. the problem if i want to render the panel again it renders the combo boxes without the store, though i'm re-constructing the panel. i tried to debug to figure out the cause and surprisingly though for combo box the Store is null on calling - comboBox.setStore(store) it checks for the property (isRendered) and finds it to be true and hence doesn't add the store but just keep the existing store which is still null.

i've seen this problem in another scenaio where i had created a collapsible field set containing the Combobox, On minimize and maximize of the fieldset the store vanishes for the same reasons.

can someone please help me here, i'm completely struck here i tried various option but nothing works. thanks in advance !

A: 

Have you tried doLayout() method of FormPanel?

Thevs
A: 

Yes i've done that already but it doesn't help. Moreover the doLayout(), i've called doLayout() as the last step, it works fine when i render the control the first time, its only when you try to re-render the same control by reconstructing it somehow still captures the old object reference for certain calls - for e.g. when i render the combobox for the first time - the property getSytle() returns null; but when i re-render it by creating the object again the same property is already filled, so there are lot of preperties which are getting fetched from the last rendered control. i've also tried calling removeAll(true) at the panel level which automatically destroys all the control which are rendered within the panel, but still no help.

A: 

ComboBox.view.setStore() should help.

If view is a private variable, just try to mention it between Combobox config params when creating. If it doesn't help - you can use plugin like that:

view_plugin = {

     init: function(o) {

          o.setNewStore = function(newStore) {
              this.view.setStore(newStore);
          };
     }
};

and add a line of

plugins: view_plugin,

to Combobox config.

Then you can call combobox.setNewStore(newStore) later in the code.

Thevs
A: 

I'm slightly confused here, first thing i don't see a property called view being exposed as public hence the statement ComboBox.view.setStore(store); couldn't not be written.

Secondly my problem is that i'm creating a new ComboBox(); and then calling the method setStore(), when calling the same method again should have similar behavior. so i'm not sure why i need to do something different each time i wish create the form panel again.. Just a snippet of my code - Below is the constructor of my ComboFieldRenderer Class public ComboFieldRenderer(boolean nullable){

            ComboBox field = null;
 Template tpl = new Template("<div class=\"x-combo-list-item\" id={value}>{value}</div>");
 field = new ComboBox();
 field.setDisplayField("value");
 field.setTriggerAction(ComboBox.ALL);
 field.setForceSelection(true);
 field.setWidth(80);

// field.setMode(ComboBox.LOCAL); field.setMode(ComboBox.REMOTE); field.setEditable(false); field.setTpl(tpl); field.setLazyRender(true); } // now from my invocation class i'm calling another method init of the class which had returned me the comboBox

public void init(Object id, Object label, Object value, Object[][] values, FieldListenerAdapter listener)
{

 SimpleStore store = new SimpleStore(new String[]{"value"},values);
 store.load();
 field.getRenderTo();
 field.removeFromParent();
 field.addListener(listener);
 field.setId(id.toString());
 field.setStore(store);
 field.setValue(value.toString());
 field.focus(true);
}

the problem is in the line field.setStore(store); as this is not assigning the store becuase of the check on the property isRendered() being done when invoked second time.

i'm not well versed in GWT-EXT so i'm sure this is not the best way to code but still on the face of it i think it should behave the same... whether invoked first time or nth..

A: 

You need to write:

field = new ComboBox({plugins: view_plugin});

in your case and define my code of view_pligin somewhere before. Or you can even incorporate it inline:

field = new ComboBox({plugins: { code of plugin });

Inside plugin all private properties and methods are accessible/changeable.

You also can change store using field.setNewStore(store) at any time later on.

Thevs
+2  A: 

Hi Thevs, Thanks for your comments, actually i tried the plugin approach but couldn't understand it completely as to how will i get the handle to the store which is not an exposed element of the component.

Anyways i tried something else, while debugging i found that though i'm creating the component again on click of show button, the ID passed is same ( which is desired ) but somehow for the given id there is already the previous reference available in the Ext.Components.

Hence an easy solution is following : Component comp = Ext.getCmp(id); if ( comp != null ) comp.destroy( );

this actually worked as the reference which was causing the ( isRendered( ) property of the ComboBox to return true is no more available and hence i can see the store again properly.

i hope this helps others who are facing similar issue. Thanks anyways for replying.