PDA

View Full Version : Displaying default value in Combo Box before clicking Down arrow


Ducky
01-22-2010, 11:21 AM
I am trying to display a default value (which is brought in via a Ext.Ajax.request) in a Combo Box prior to the user clicking the Down arrow to see the choices. There is a single letter Area value coming in through the Ajax request which I want to use to find an Area name in an already loaded Json data store and display the name corresponding to the code passed in. I have tried putting a listener on the Combo Box before show and before load but my Ajax request did not fire off. If I put the listener for the Ajax request on the window, it fires before the store is loaded into the combo box so all I get is the code itself. Here below is my code:

Ext.onReady(function() {


new Ext.Window({
listeners: {
beforeshow: function(){
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {
action: 'getdefault',
pgm: 'CHGAREA'
},
success: function(response){
var check = response.responseText;
if (check) {
var data = Ext.util.JSON.decode(response.responseText);
}
if (data.SUCCESS == '1') {
Ext.getCmp('dArea').setValue(data.ARAREA);
}
else {
vvShowError('ERROR OCCURED', 'Current work area default not found.');
}
}
})
}
},

title: 'Change Work Area',
iconCls:'application_view_detail',
closable:false,
resizable:false,
x:100,
y:150,
layout:'table',
bodyStyle: 'padding:20px',
height:100,
width:450,
items: [{
xtype: 'combo',
emptyText: 'Select the work area',
labelSeparator: ' ',
id: 'dArea',
triggerAction: 'all',
displayField: 'ARNAME',
valueField: 'ARAREA',
store: new Ext.data.JsonStore({
autoLoad: true,
url: 'vvcall.pgm',
baseParams: {
pgm: 'CHGAREA',
action: 'load'
},
root: 'MLPAREA',
fields: ['ARAREA', 'ARNAME']
}),
listeners: {
select: {
fn: function(){
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {
action: 'save',
pgm: 'CHGAREA',
narea: Ext.getCmp('dArea')
}
})
}
}
}
}]
}).show();

});

richard.milone
01-22-2010, 05:38 PM
Ducky, welcome to the forum. You were very close. You really need to put that ajax call for loading your default as a "load" listener on the combo box store. This guarantees that the store is loaded completely before you attempt to set the default. I posted the changed code below. See if this works for you.

Ext.onReady(function() {


new Ext.Window({
title: 'Change Work Area',
iconCls: 'application_view_detail',
closable: false,
resizable: false,
x: 100,
y: 150,
layout: 'table',
bodyStyle: 'padding:20px',
height: 100,
width: 450,
items: [{
xtype: 'combo',
emptyText: 'Select the work area',
labelSeparator: ' ',
id: 'dArea',
triggerAction: 'all',
displayField: 'ARNAME',
valueField: 'ARAREA',
store: new Ext.data.JsonStore({
autoLoad: true,
url: 'vvcall.pgm',
baseParams: {
pgm: 'CHGAREA',
action: 'load'
},
root: 'MLPAREA',
fields: ['ARAREA', 'ARNAME'],
listeners: {
load: function() {
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {
action: 'getdefault',
pgm: 'CHGAREA'
},
success: function(response) {
var check = response.responseText;
if (check) {
var data = Ext.util.JSON.decode(response.responseText);
}
if (data.SUCCESS == '1') {
Ext.getCmp('dArea').setValue(data.ARAREA);
} else {
vvShowError('ERROR OCCURED', 'Current work area default not found.');
}
}
})
}
}
}),
listeners: {
select: {
fn: function() {
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {
action: 'save',
pgm: 'CHGAREA',
narea: Ext.getCmp('dArea')
}
})
}
}
}
}]
}).show();
});

Ducky
01-25-2010, 03:48 PM
Thanks, Richard. It worked very well. There is one curious related issue. Once the selection is made, an AJAX call is made to use an RPG program (CHGAREA) to update a session variable. This AJAX call had been working previously. When I first tested your suggested changes, I thought maybe I had messed up the 'Save' action when I put in your changes because of the internal server error that appeared in the Mozilla Firebug debugger(See below). When I ran a remote system debug (RDI) on the Save procedure in CHGAREA, however, it proved to be updating the session variable correctly. I received further confirmation of a correct update when I closed the screen and re-opened it and the new default appeared. Does anyone have any idea why it might be throwing this error?


<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>500 Internal Server Error</TITLE>
</HEAD><BODY>
<H1>Internal Server Error</H1>
Cannot read script output pipe.
</body></html>

sean.lanktree
01-25-2010, 04:24 PM
Make sure that the process that updates your session variable actually responds something back to the browser. For example, when the update is successful, send back:


vvOut_toJsonPair('SUCCESS:1')

Ducky
01-28-2010, 04:36 PM
Thanks Sean, that did the trick!