PDA

View Full Version : Please Help : How to get back url of my store in a xml file?



xav_allais
14 Jun 2010, 6:31 AM
Please, i need your help!


I have this xml file (conf.xml) :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Params>
<XmlGridFiles>
<default>NW_Products.xml</default>
<all>
<File>NW_Products.xml</File>
<File>NW_Products_Spring.xml</File>
<File>NW_Products_Summer.xml</File>
<File>NW_Products_Fall.xml</File>
<File>NW_Products_Winter.xml</File>
</all>
</XmlGridFiles>
</Params>


I want to use the default xml file field for the url of my store (<default>NW_Products.xml</default> -> myDefaultXmlFile)

var storeMain = new Ext.data.Store({
// load using HTTP
url: myDefaultXmlFile,
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
//
record: 'Row',
id: 'ProductID',
//
fields: [
//
{name: 'myProductName', type: 'string'},
{name: 'CA', type: 'float'}
]
}, [
//
{name: 'myProductName', mapping: 'ProductName'},
'CA'
])
});
storeMain.load();


How can i make that : <default>NW_Products.xml</default> -> myDefaultXmlFile ?

Many Thanks for your help

xav_allais
15 Jun 2010, 6:43 AM
Nobody knows ???

ddanatzko
15 Jun 2010, 7:46 AM
What exactly are you trying to do? It looks like you're trying to create an XML data store from another XML data store. If that's the case, you're going to need yet another Store/Reader to parse the results of XML data store that contains the URL of the Data Store you want to assign a dynamic URL from.

xav_allais
16 Jun 2010, 12:05 AM
Thanks for your reply. You're right. But, in fact, i know load a store and use it in a grid or in a combo box, but i don't know read a store.
I want do something as that (storeConf is the store with my conf.xml) :


var myDefaultXmlFile = '';
myDefaultXmlFile = storeConf.index(0).field('default')

But index and field doesn't exist... How are the equivalent ?

Many Thanks for your help ;)

Elijah
16 Jun 2010, 4:28 AM
I am running into this same issue however, I am using JSON data that is returned. I believe based on what I understand of it now and the responses that I have recieved that you will need to do the following.

Set a variable to hold all of the data from a call using the Ext AJAX call that will fetch all of your xml data.
Set your default variable to the value.
Set the data store to its value.


I believe this is because your <default>NW_Products.xml</default> is outside of your root which is<all>

Also, use the FireFox FireBug plugin to view the response from the server which will show you the content of the xml you are retrieving.

xav_allais
16 Jun 2010, 5:53 AM
Thanks for your help Elijah, but I have no problem with my xml file. I load my store and if I apply my store in a combo box, it works : my combo box contain "NW_Product.xml". So, my xml file and my storeConf are Ok.
I just need to learn how put a field of my store in a variable instead a combo box...
++

fay
16 Jun 2010, 6:09 AM
var myVar = store.getAt(indexOfRecord).get(nameOfField);


It's all in the docs (http://www.sencha.com/deploy/dev/docs/).

xav_allais
16 Jun 2010, 7:58 AM
Thanks fay, I studied a lot the doc and I already tried that but I have always an error : "storeConf.getAt(1) is undefined". Yet, storeConf works for my combo box...

Here is my new xml file :


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Params>
<XmlGridFiles>
<defaultXml>NW_Products.xml</defaultXml>
<allXml>
<XmlFile>NW_Products.xml</XmlFile>
<XmlFile>NW_Products_Spring.xml</XmlFile>
<XmlFile>NW_Products_Summer.xml</XmlFile>
<XmlFile>NW_Products_Fall.xml</XmlFile>
<XmlFile>NW_Products_Winter.xml</XmlFile>
</allXml>
</XmlGridFiles>
</Params>

Here is my Store :


var recordConfStructure = Ext.data.Record.create([
{name: 'defaultXml'}
]);

var recordConfArray = new Ext.data.XmlReader({
// records will have an "XmlGridFiles" tag
record: 'XmlGridFiles',
id: 'defaultXml',
// use an Array of field definition objects to implicitly create a Record constructor
fields: [
// the 'name' below matches the tag name to read, except 'availDate'
// which is mapped to the tag 'availability'
{name: 'defaultXml', type: 'string'}
]
}, recordConfStructure);

var storeConf = new Ext.data.Store({
// load using HTTP
url: 'conf.xml',

// the return will be XML, so lets set up a reader
reader: recordConfArray
});
storeConf.load();

Here is my combo box which works :

var comboTest = new Ext.form.ComboBox({
id:'combo-test'
,region: 'north'
,fieldLabel:'Test'
,displayField:'defaultXml'
,valueField:'defaultXml'
,store: storeConf
,emptyText:'Just for test...'
,triggerAction:'all'
,mode:'local'
,lastQuery:''
});

So, all works and i test that :

var myVar = storeConf.getAt(1).get('defaultXml');
Ext.MessageBox.alert('Test', myVar);

And I have this error : "storeConf.getAt(1) is undefined"

I have also tried :

var myVar = storeConf.getAt(0).get('defaultXml');
Ext.MessageBox.alert('Test', myVar);

But I have the same error : "storeConf.getAt(0) is undefined"

Thanks for your help please

xav_allais
17 Jun 2010, 5:35 AM
If I good understand what I read, the cause of my problem is that the load of the store is Asynchronous...

I have made this test and we observe that getAt methode works after render but not before.

So, here is the xml file for my test (conf.xml):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Params>
<GridFiles>
<GridFile>
<IDFile>1</IDFile>
<NameFile>NW_Products.xml</NameFile>
</GridFile>
<GridFile>
<IDFile>2</IDFile>
<NameFile>NW_Products_Spring.xml</NameFile>
</GridFile>
<GridFile>
<IDFile>3</IDFile>
<NameFile>NW_Products_Summer.xml</NameFile>
</GridFile>
<GridFile>
<IDFile>4</IDFile>
<NameFile>NW_Products_Fall.xml</NameFile>
</GridFile>
<GridFile>
<IDFile>5</IDFile>
<NameFile>NW_Products_Winter.xml</NameFile>
</GridFile>
</GridFiles>
</Params>

Here is my full javascript file (myTst.js):

Ext.onReady(function(){
Ext.QuickTips.init();

// My Reader and my Store
//========================
var recordConfReader = new Ext.data.XmlReader({
// records will have an "GridFile" tag
record: 'GridFile',
id: 'IDFile',
// use an Array of field definition objects to implicitly create a Record constructor
fields: [
// the 'name' below matches the tag name to read, except 'availDate'
// which is mapped to the tag 'availability'
{name: 'IDFile', type: 'string'},
{name: 'NameFile', type: 'string'}
]});

var storeConf = new Ext.data.Store({
// load using HTTP
url: 'conf.xml',

// the return will be XML, so lets set up a reader
reader: recordConfReader
});
storeConf.load();

// Test myVar = first value of my Store... -> Don't Work : storeConf.getAt(...) is undefined !
// -> Asynchronous Problem : Store not Ok immediatly after the load... -> What must I do ???
//===================================================================================================
//var myVar = ''
//myVar = storeConf.getAt(storeConf.find('IDFile','1')).get('NameFile');
//Ext.MessageBox.alert('Test', myVar);

// Combobox Test
//===============
var valueComboTest = '';
var txtComboTest = '';

var comboTest = new Ext.form.ComboBox({
id:'combo-test'
,region: 'north'
,fieldLabel:'Test'
,displayField:'NameFile'
,valueField:'IDFile'
,store: storeConf
,emptyText:'Just for test...'
,triggerAction:'all'
,mode:'local'
,lastQuery:''
,listeners:{
select:{fn:function(combo, value)
{
valueComboTest = combo.getValue();
//txtComboTest = storeConf.getAt(storeConf.find('IDFile',valueComboTest)).get('NameFile');// for recup the NameFile for the IDFile selected by the combo
txtComboTest = storeConf.getAt(storeConf.find('IDFile','1')).get('NameFile');// for recup the NameFile for the IDFile 1
Ext.MessageBox.alert('Tests', 'txt : '+txtComboTest+' ; value : '+valueComboTest);
}
}}
});

// Panel and Render
//==================
var panel = new Ext.Panel({
id:'my-panel',
frame:true,
width:535,
autoHeight:true,
collapsible:true,
layout:'fit',
title:'Tests Asynchronous Problem',
items: [comboTest]
});

panel.render(document.body);
});

And here is my html file (index.html):

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Asynchronous Test 01</title>
<!-- Common Styles ExtJS -->
<link rel="stylesheet" type="text/css" href="../extJS/resources/css/ext-all.css" />

<!-- GC -->
<!-- LIBS -->
<script type="text/javascript" src="../extJS/adapter/ext/ext-base.js"></script>
<!-- ENDLIBS -->

<!-- Common JavaScript ExtJS -->
<script type="text/javascript" src="../extJS/ext-all.js"></script>

<!-- JavaScript for the Mock-Up -->
<script type="text/javascript" src="myTst.js"></script>

</head>

<body>

</body>

</html>

If you test that, you see that it works and that when you select something in the combo a message inform you about the value and the text selected.

BUT... If you change this section in the javascript file :

// Test myVar = first value of my Store... -> Don't Work : storeConf.getAt(...) is undefined !
// -> Asynchronous Problem : Store not Ok immediatly after the load... -> What must I do ??? //==========================================================================
//var myVar = ''
//myVar = storeConf.getAt(storeConf.find('IDFile','1')).get('NameFile');
//Ext.MessageBox.alert('Test', myVar);

And write instead :

// Test myVar = first value of my Store... -> Don't Work : storeConf.getAt(...) is undefined !
// -> Asynchronous Problem : Store not Ok immediatly after the load... -> What must I do ??? //==========================================================================
var myVar = ''
myVar = storeConf.getAt(storeConf.find('IDFile','1')).get('NameFile');
Ext.MessageBox.alert('Test', myVar);

You see the error here !

Please, I need for your help. I think i can't succeed alone...

fay
18 Jun 2010, 1:49 AM
Use the store's (http://www.sencha.com/deploy/dev/docs/?class=Ext.data.Store) 'load' event:



storeConf.on('load', function(store, records, options)
{
// Set your variables here.
});

xav_allais
22 Jun 2010, 12:01 AM
Thank you very much fay.

Below is all my test's files ; it could help some one else ;)

Here is my xml file :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Params>
<GridFiles>
<GridFile>
<IDFile>1</IDFile>
<NameFile>NW_Products.xml</NameFile>
</GridFile>
<GridFile>
<IDFile>2</IDFile>
<NameFile>NW_Products_Spring.xml</NameFile>
</GridFile>
<GridFile>
<IDFile>3</IDFile>
<NameFile>NW_Products_Summer.xml</NameFile>
</GridFile>
<GridFile>
<IDFile>4</IDFile>
<NameFile>NW_Products_Fall.xml</NameFile>
</GridFile>
<GridFile>
<IDFile>5</IDFile>
<NameFile>NW_Products_Winter.xml</NameFile>
</GridFile>
</GridFiles>
</Params>

Here is my html file :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Asynchronous Test 02</title>
<!-- Common Styles ExtJS -->
<link rel="stylesheet" type="text/css" href="../extJS/resources/css/ext-all.css" />

<!-- GC -->
<!-- LIBS -->
<script type="text/javascript" src="../extJS/adapter/ext/ext-base.js"></script>
<!-- ENDLIBS -->

<!-- Common JavaScript ExtJS -->
<script type="text/javascript" src="../extJS/ext-all.js"></script>

<!-- JavaScript for the Mock-Up -->
<script type="text/javascript" src="myTst.js"></script>

</head>

<body>

</body>

</html>

And here is my javascript file :

/*!
* Ext JS Library 3.2.1
* Copyright(c) 2006-2010 Ext JS, Inc.
* [email protected]
* http://www.extjs.com/license
*/

Ext.onReady(function(){
Ext.QuickTips.init();

// My Reader and my Store
//========================
var recordConfReader = new Ext.data.XmlReader({
// records will have an "GridFile" tag
record: 'GridFile',
id: 'IDFile',
// use an Array of field definition objects to implicitly create a Record constructor
fields: [
// the 'name' below matches the tag name to read, except 'availDate'
// which is mapped to the tag 'availability'
{name: 'IDFile', type: 'string'},
{name: 'NameFile', type: 'string'}
]});

var storeConf = new Ext.data.Store({
// load using HTTP
url: 'conf.xml',

// the return will be XML, so lets set up a reader
reader: recordConfReader
});

storeConf.load();

// Test myVar = first value of my Store... -> Don't Work : storeConf.getAt(...) is undefined !
// -> Asynchronous Problem : Store not Ok immediatly after the load... -> See below :
//===================================================================================================

// Don't do that : it don't works because of it's Asynchronous !
//---------------------------------------------------------------
//var myVar = ''
//myVar = storeConf.getAt(storeConf.find('IDFile','1')).get('NameFile');
//Ext.MessageBox.alert('Test', myVar);

// We must do that because of it's Asynchronous !
//-----------------------------------------------
storeConf.on("load", function(s,rs) {
var myVar = ''
myVar = storeConf.getAt(storeConf.find('IDFile','1')).get('NameFile');
Ext.MessageBox.alert('Test', myVar);
});


// Combobox Test
//===============
var valueComboTest = '';
var txtComboTest = '';

var comboTest = new Ext.form.ComboBox({
id:'combo-test'
,region: 'north'
,fieldLabel:'Test'
,displayField:'NameFile'
,valueField:'IDFile'
,store: storeConf
,emptyText:'Just for test...'
,triggerAction:'all'
,mode:'local'
,lastQuery:''
,listeners:{
select:{fn:function(combo, value)
{
valueComboTest = combo.getValue();
//txtComboTest = storeConf.getAt(storeConf.find('IDFile',valueComboTest)).get('NameFile');// for recup the NameFile for the IDFile selected by the combo
txtComboTest = storeConf.getAt(storeConf.find('IDFile','1')).get('NameFile');// for recup the NameFile for the IDFile 1
Ext.MessageBox.alert('Tests', 'txt : '+txtComboTest+' ; value : '+valueComboTest);
}
}}
});

// Panel and Render
//==================
var panel = new Ext.Panel({
id:'my-panel',
frame:true,
width:535,
autoHeight:true,
collapsible:true,
layout:'fit',
title:'Tests Asynchronous Problem',
items: [comboTest]
});

panel.render(document.body);
});

Many thanks four our help ;)