PDA

View Full Version : Welcome



chuvinha
14 Feb 2011, 9:26 AM
Hi guys, I need to put a message (label) "Welcome + user's name + user's surname" in the home page.
These data come from json.
I will put this message inside of a panel.
Would anyone have an example of how to do this?

fay
14 Feb 2011, 11:14 AM
To get the JSON, take a look at Arthur's post from earlier - http://www.sencha.com/forum/showthread.php?123740-Get-json-string-from-a-URL-and-store-in-an-object-or-array&p=570826&viewfull=1#post570826. To put the label in a panel, take a look at the Ext.Panel (http://dev.sencha.com/deploy/dev/docs/?class=Ext.Panel) update() method.

chuvinha
15 Feb 2011, 4:33 AM
It wasn't work.
On painel I put onBeforerender="trazerNomeUsuarioLogado();"
My code:




function trazerNomeUsuarioLogado(){

var dataObj = null;

Ext.Ajax.request({
url:'resulthome.action',
failure: function(response, options) {},
success: function(response, options) {
dataObj = Ext.decode(response.responseText);
Ext.getCmp('panelInicio').update(dataObj.nome);
}
});
}


The JSON:



[{"id" : 29,"nome" : "Rafael Duarte"}]

I don't know because it is work.

Fredric Berling
15 Feb 2011, 5:05 AM
Your panel should use a template in the tpl config.


tpl:'<div class="fancylabel">Welcome {nome}</div>'


then you should send the complete data object to the update function :


Ext.getCmp('panelInicio').update(dataObj);

chuvinha
15 Feb 2011, 5:51 AM
It wasn't work.
When I don't put the "tpl" it appears [object Object] from panel.
And when I put the "tpl" it appears nothing.




function trazerNomeUsuarioLogado(){

var panelHomeInicio = new Ext.Panel({
id: 'panelInicio',
tpl:'<div>{nome}</div>'
});

var dataObj = null;

Ext.Ajax.request({
url:'resulthome.action',
failure: function(response, options) {},
success: function(response, options) {
dataObj = Ext.decode(response.responseText);
panelHomeInicio.update(dataObj);
}
});
}


I don't know because it is work.

chuvinha
16 Feb 2011, 2:33 AM
Fredric, your code it was work?