PDA

View Full Version : newbie question : "g.body is null" error for a very simple page



flamant
7 Nov 2010, 5:59 AM
Hi,

I coded a very simple extjs page :



<script type="text/javascript">


var acceuil = new Ext.Panel({
title: '<spring:message code="application.acceuil"/>',
id: 'acceuil'
});

console.log('acceuilTab');
console.log(acceuil);

var rechercherService = new Ext.Panel({
title: '<spring:message code="application.service.rechercher"/>',
id: 'rechercherService'
});

console.log('rechercherService');
console.log(rechercherService);

var deposerAnnonce =new Ext.Panel( {
title: '<spring:message code="application.annonce.deposer"/>',
id: 'deposerAnnonce'
});

console.log('deposerAnnonce');
console.log(deposerAnnonce);

var correspondance = new Ext.Panel({
title: '<spring:message code="application.correspondance"/>',
id: 'correspondance'
});

console.log('correspondance');
console.log(correspondance);

var forum = new Ext.Panel({
title: '<spring:message code="application.forum"/>',
id: 'forum'
});
console.log('forum');
console.log(forum);
console.log('ca passe');
var tabPanel = new Ext.TabPanel({
activeTab: 0,
id: 'acceuilTabPanel',
enableTabScroll: true,
items: [
acceuil,
rechercherService,
deposerAnnonce,
correspondance,
forum ]
});

console.log('tabPanel');
console.log(tabPanel);

var myWindow = new Ext.Window({
layout: 'fit',
items: tabPanel
});



console.log('window');
console.log(myWindow);

myWindow.show();
</script>


and I get a "g.body is null" error. As you can see, I put console log and everything seems to be correct until the "myWindow.show();" line. This example is coming from EXTJSinAction book

Thank you in advance for your answer

plalx
7 Nov 2010, 6:13 AM
Have you wrapped your code in a function provided to Ext.onReady() ? You have to do so to be sure the DOM is ready so that you can interact with it.

flamant
7 Nov 2010, 7:58 AM
Thank you very much scarsick now the window is displayed

But the window doesn't fit the page browser

I tried window.render(document.body) without success

plalx
7 Nov 2010, 8:59 AM
As soon as show() is called, the window is rendered in the DOM. Try win.maximize() once the window is shown to fit the window size to its container.

flamant
7 Nov 2010, 9:44 AM
effectively when I call win.maximize() the window fit the browser page.

moreover I don't understand why I didn't before because I called win.render(document.body) before win.show();



myWindow.render(document.body);
myWindow.show();