Hi,
I am trying to integratae my Grails application with extJS. Below is the code in my edit.gsp file.
<%@ page import="tune.Music"%>
<script type="text/javascript">
var ds = new Ext.data.Store({
autoLoad: true,
proxy: new Ext.data.HttpProxy({
url: 'http://localhost:8080/tune/music/listData'}),
reader: new Ext.data.JsonReader({
results: 'total',
root:'items',
id:'id'
},
[
{name: 'playerId'},
{name: 'playerPrice'}
]
)
});
var cm = new Ext.grid.ColumnModel([
{header: "Player Id", width: 70, sortable:true, dataIndex: 'playerId'},
{header: "Player Price", width: 90, dataIndex: 'playerPrice'}
]);
//cm.defaultSortable = true;
// create the grid
var grid = new Ext.grid.GridPanel({
ds: ds,
cm: cm,
renderTo:'grid-example',
width:1300,
height:300
});
</script>
</head>
<body>
<div class="body">
<!--<g:javascript library="examples"/>-->
<!-- EXAMPLES -->
<h1>Ext Grid</h1>
<div id="grid-example"></div>
</div>
</body>
My controller action:
def list={ }
def listData = { def session = sessionFactory.getCurrentSession() def result = session.createSQLQuery("select player_id from w.music where player_id=('530AS')").list(); def tuneInstanceList = new ArrayList() result.each { def tune = new Tune() tune.playerId = it tune.playerPrice = "100" tuneInstanceList.add(tune) } def listResult = [total: tunInstanceList.size(), items: tunInstanceList] render listResult as JSON; }
The above code works for me.
However, This works in my development environment. If I run this in another env it doesnt work because of the url that I have hardcoded here viz url: 'http://localhost:8080/tune/music/listData'.
One of the options is to use gsparse. However, i would like to mention a relative urlPath here if thats possible. What do I replace my urlPath with so that the right action is called even in other environments.
Thanks!