View Full Version : GridPanel - Posting a Value to the Proxy

16 May 2011, 5:40 AM
Hi, I will try and explain my problem as best as possible, so here goes...

Inside my js file to create and config the grid, I have the following proxy:

var materialsProxy = new Ext.data.HttpProxy ({
api: {
// url in the Controller
read : 'grid/ajax'

This calls a method in my controller which is mapped to the URL 'grid/ajax', which returns the JSON needed to populate the grid.

All my grids work in a similar fashion, which is great. However, for this particular case, I generate the grid onSelect of a drop-down list, and not by using 'Ext.onReady'.

This means I have to pass the 'id' of the chosen option selected, in order to return the relevant grid.

Is this possible/Any help on achieving this?

Thanks in advance..

16 May 2011, 2:07 PM
I'm not sure if this is the best/right way to do it, but I've done this before by setting a "baseParam" on the store before calling the store load function. So something like this:

store.setBaseParam("id", id);


17 May 2011, 2:44 AM
Thanks for your reply,
I've had a read around about setBaseParam and am not completely sure if it can be used for my problem, so if you could help me answer a couple of questions, that would be great.

How will I be able to access the parameter from my controller method (which the proxy calls) before loading the grid?

For instance, if I call:

store.setBaseParam("id", id);

I have to be able to use the 'id' set to fetch its data from the database (which is then converted to JSON and returned).

An example controller method is below:

@RequestMapping( value = {
}, method = RequestMethod.GET )
public Map<String, Object> viewGridSAPLinks( //
@PathVariable( "orgId" ) int orgId, //
@ModelAttribute( "clientSAPLinkCommand" ) ClientSAPLinkCommand clientSAPLinkCommand)


Map<String, Object> modelMap = new ModelMap() ;
modelMap.put( "success", true ) ;
modelMap.put( "total", clientSAPLinkCommand.getSapLinkDTOs().size() ) ;
modelMap.put( "data", clientSAPLinkCommand.getSapLinkDTOs() ) ;

return modelMap ;

So I would need the 'id' value to be available in this method. Is this possible using setBaseParam? Or can you see an easier way?

Thanks for your help.

17 May 2011, 6:00 AM
The baseParams are sent as url parameters. You should be able to access the id baseParam from your controller method with something like:

public Map<String, Object> viewGridSAPLinks(@RequestParam Long id){}

You can also set baseParams as an attribute on your store when it's created if you need to, so that the parameter will be sent whenever a request is sent.

17 May 2011, 7:19 AM
This is exactly what I want, thanks!

I changed the RequestMethod in my controller to POST as to send the value across.

Yet another Ext Js problem solved, thanks again 'kembuco'.

17 May 2011, 7:52 PM
No problem. Nice to see some other Spring MVC folks using ExtJS.