Reputation: 1
I am working on a book repository application using ExtJS4, Spring JPA, Restful services, Hibernate technologies. I need to create a gridpanel in Extjs which list all the books upon loading the page and there should be a form below the grid which has the ability to add a book. Once the user hits Add button on the form the grid should automatically refresh and show the new book.
Its kind of challenging for me to build everything from scratch. I have built the server side code and getting a response for listBooks and saveBook methods. Now I need to build the ExtJS page that calls my services defined in Spring to show the list of books and add a book. I am struggling with the integration of ExtJS with the server side. I am not able to call the services through extjs. I would really appreciate your help! I am attaching some screenshots. Also I have created Dao and Service classes for their respective Impl classes.
Ext.onReady(function(){
Ext.create(Ext.window.Window, {
title : 'Add Book',
width : 350,
x : 50,
y : 275,
layout : 'fit',
resizable: false,
closeAction: 'hide',
modal : true,
config : {
recordIndex : 0,
action : ''
},
items : [{
xtype : 'form',
layout: 'anchor',
bodyStyle: {
background: 'none',
padding: '10px',
border: '0'
},
defaults: {
xtype : 'textfield',
anchor: '100%'
},
items : [{
name : 'isbn',
fieldLabel: 'ISBN'
},{
name: 'title',
fieldLabel: 'Title'
},{
name: 'author',
fieldLabel: 'Author'
},{
name: 'genre',
fieldLabel: 'Genre'
},{
name: 'details',
fieldLabel: 'Details'
}]
}],
buttons: [{
text: 'Add Book',
action: 'add'
/* handler : function(){
click : this.doAddBook(),
doAddBook: function(){
Ext.window.MessageBox("Hello");
}
}*/
}]
}).show();
renderTo: Ext.getBody();
});
Ext.define('BookModel', {
extend : 'Ext.data.Model',
fields : [
{name: 'isbn', type : 'int'},
{name: 'title', type : 'string'},
{name: 'author', type : 'string'},
{name: 'genre', type : 'string'},
{name: 'details', type : 'string'}
]
});
Ext.define('Bookstore', {
extend : 'Ext.data.Store',
storeId : 'bookStore',
model : 'BookModel',
fields : ['isbn', 'title', 'author','genre', 'details'],
proxy : {
type : 'ajax',
url : 'http://localhost:2016/SpringRestServiceNew/book/list',
reader : {
type : 'json',
root : 'books'
}
},
autoLoad : true
});
Ext.define('BooksList', {
extend : 'Ext.grid.Panel',
title: 'Books List',
store : 'Bookstore',
columns : [
{header : 'ISBN', dataIndex: 'isbn', flex: 1},
{header: 'Title', dataIndex: 'title'},
{header: 'Author', dataIndex: 'author'},
{header: 'Genre', dataIndex: 'genre'},
{header: 'Details', dataIndex: 'details'}],
height : 250,
width : 400,
renderTo : Ext.getBody()
});
<!--
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Library Application</title>
<link rel="stylesheet"
href="http://cdn.sencha.io/try/extjs/4.1.0/resources/css/ext-all-gray.css" />
<script src="http://cdn.sencha.io/try/extjs/4.1.0/ext-all-debug.js"></script>
<script type="text/javascript" src="mycode.js"></script>
</head>
<body>
</body>
</html>
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Library Application</title>
<link rel="stylesheet" type="text/css" href="http://cdn.sencha.com/ext/gpl/4.2.0/resources/css/ext-all.css">
<script type="text/javascript" src="http://cdn.sencha.com/ext/gpl/4.2.0/ext-all-debug.js"></script>
<!--<script type="text/javascript" src="http://cdn.sencha.com/ext/gpl/4.2.0/ext-all.js"></script> -->
<script type="text/javascript" src="mycode.js"></script>
</head>
<body>
</body>
</html>
Upvotes: 0
Views: 69
Reputation: 1441
There are few issues with your code.
Here is updated code.
Ext.define('BookPanel', {
extend: 'Ext.Panel',
xtype: 'bookForm',
title: 'Add Book',
resizable: false,
config: {
recordIndex: 0,
action: ''
},
items: [{
xtype: 'form',
layout: 'anchor',
bodyStyle: {
background: 'none',
padding: '10px',
border: '0'
},
defaults: {
xtype: 'textfield',
anchor: '100%'
},
items: [{
name: 'isbn',
fieldLabel: 'ISBN'
}, {
name: 'title',
fieldLabel: 'Title'
}, {
name: 'author',
fieldLabel: 'Author'
}, {
name: 'genre',
fieldLabel: 'Genre'
}, {
name: 'details',
fieldLabel: 'Details'
}]
}],
buttons: [{
text: 'Add Book',
action: 'add'
/* handler : function(){
click : this.doAddBook(),
doAddBook: function(){
Ext.window.MessageBox("Hello");
}
}*/
}]
});
Ext.define('BookModel', {
extend: 'Ext.data.Model',
fields: [{
name: 'isbn',
type: 'int'
}, {
name: 'title',
type: 'string'
}, {
name: 'author',
type: 'string'
}, {
name: 'genre',
type: 'string'
}, {
name: 'details',
type: 'string'
}]
});
var data = {
books: [{
isbn: 1,
title: 'Ed Spencer',
author: '555 1234'
}, {
isbn: 2,
title: 'Abe Elias',
author: '666 1234'
}]
};
Ext.define('BookStore', {
extend: 'Ext.data.Store',
storeId: 'bookStore',
model: 'BookModel',
data: data,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'books'
}
}
});
Ext.define('BookList', {
extend: 'Ext.grid.Panel',
xtype: 'bookList',
title: 'Books List',
store: new BookStore(),
columns: [{
header: 'ISBN',
dataIndex: 'isbn',
flex: 1
}, {
header: 'Title',
dataIndex: 'title'
}, {
header: 'Author',
dataIndex: 'author'
}, {
header: 'Genre',
dataIndex: 'genre'
}, {
header: 'Details',
dataIndex: 'details'
}],
height: 250,
width: 400
});
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.create('Ext.Panel', {
layout: 'vbox',
items: [{
xtype: 'bookList',
width: '100%',
flex: 1
}, {
xtype: 'bookForm',
width: 500,
flex: 1
}],
renderTo: Ext.getBody()
});
}
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Library Application</title>
<link rel="stylesheet" type="text/css" href="http://cdn.sencha.com/ext/gpl/4.2.0/resources/css/ext-all.css">
<script type="text/javascript" src="http://cdn.sencha.com/ext/gpl/4.2.0/ext-all-debug.js"></script>
</head>
<body>
</body>
</html>
Upvotes: 1