0

I have created an application designed in Spring MVC3, Hibernate and Ext Js. It's a books library. I use Eclipse IDE. In the WebContent folder i created the extjs application named app , there I uploaded extjs files too. My application contains 4 packages: controller, model, store and view.

Controller Books.js:

Ext.define('ExtJS.controller.Books', {
extend: 'Ext.app.Controller',

stores: ['Books'],

models: ['Book'],

views: ['book.Edit', 'book.List'],

refs: [{
        ref: 'booksPanel',
        selector: 'panel'
    },{
        ref: 'booklist',
        selector: 'booklist'
    }
],

init: function() {
    this.control({
        'booklist dataview': {
            itemdblclick: this.editUser
        },
        'booklist button[action=add]': {
            click: this.editUser
        },
        'booklist button[action=delete]': {
            click: this.deleteUser
        },
        'bookedit button[action=save]': {
            click: this.updateUser
        }
    });
},

editUser: function(grid, record) {
    var edit = Ext.create('ExtJS.view.book.Edit').show();

    if(record){
        edit.down('form').loadRecord(record);
    }
},

updateUser: function(button) {
    var win    = button.up('window'),
        form   = win.down('form'),
        record = form.getRecord(),
        values = form.getValues();


    if (values.id > 0){
        record.set(values);
    } else{
        record = Ext.create('ExtJS.model.Book');
        record.set(values);
        record.setId(0);
        this.getBooksStore().add(record);
    }

    win.close();
    this.getBooksStore().sync();
},

deleteUser: function(button) {

    var grid = this.getBooklist(),
    record = grid.getSelectionModel().getSelection(), 
    store = this.getBooksStore();

    store.remove(record);
    this.getBooksStore().sync();
}
});

Model Book.js:

Ext.define('ExtJS.model.Book', {
extend: 'Ext.data.Model',
fields: ['id', 'title', 'author', 'publisher', 'isbn', 'pages', 'category', 'qty']
});

Store Books.js:

Ext.define('ExtJS.store.Books', {
extend: 'Ext.data.Store',
model: 'ExtJS.model.Book',
autoLoad: true,
pageSize: 35,
autoLoad: {start: 0, limit: 35},

proxy: {
    type: 'ajax',
    api: {
        read : 'books/view.action',
        create : 'books/create.action',
        update: 'books/update.action',
        destroy: 'books/delete.action'
    },
    reader: {
        type: 'json',
        root: 'data',
        successProperty: 'success'
    },
    writer: {
        type: 'json',
        writeAllFields: true,
        encode: false,
        root: 'data'
    },
    listeners: {
        exception: function(proxy, response, operation){
            Ext.MessageBox.show({
                title: 'REMOTE EXCEPTION',
                msg: operation.getError(),
                icon: Ext.MessageBox.ERROR,
                buttons: Ext.Msg.OK
            });
        }
    }
}
});

View contains the Viewport.js:

Ext.define('ExtJS.view.Viewport', {
extend: 'Ext.container.Viewport'
});

and a folder named book where I have:

List.js:

Ext.define('ExtJS.view.book.List' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.booklist',

//requires: ['Ext.toolbar.Paging'],

iconCls: 'icon-grid',

title : 'Books',
store: 'Books',

columns: [{
    header: "Title",
    width: 50,
    flex:1,
    dataIndex: 'title'
},{
    header: "Author",
    width: 50,
    flex:1,
    dataIndex: 'author'
},{
    header: "Publisher",
    width: 50,
    flex:1,
    dataIndex: 'publisher'
},{
    header: "Isbn",
    width: 50,
    flex:1,
    dataIndex: 'isbn'
},{
    header: "Pages",
    width: 50,
    flex:1,
    dataIndex: 'pages'
},{
    header: "Category",
    width: 50,
    flex:1,
    dataIndex: 'category'
},{
    header: "Qty",
    width: 50,
    flex:1,
    dataIndex: 'qty'
}],

initComponent: function() {

    this.dockedItems = [{
        xtype: 'toolbar',
        items: [{
            iconCls: 'icon-save',
            itemId: 'add',
            text: 'Add',
            action: 'add'
        },{
            iconCls: 'icon-delete',
            text: 'Delete',
            action: 'delete'
        }]
    },
    {
        xtype: 'pagingtoolbar',
        dock:'top',
        store: 'Books',
        displayInfo: true,
        displayMsg: 'Displaying books {0} - {1} of {2}',
        emptyMsg: "No books to display"
    }];

    this.callParent(arguments);
}
});

and

Edit.js:

Ext.define('ExtJS.view.book.Edit', {
extend: 'Ext.window.Window',
alias : 'widget.bookedit',

requires: ['Ext.form.Panel','Ext.form.field.Text'],

title : 'Edit Book',
layout: 'fit',
autoShow: true,
width: 280,

iconCls: 'icon-user',

initComponent: function() {
    this.items = [
        {
            xtype: 'form',
            padding: '5 5 0 5',
            border: false,
            style: 'background-color: #fff;',

            fieldDefaults: {
                anchor: '100%',
                labelAlign: 'left',
                allowBlank: false,
                combineErrors: true,
                msgTarget: 'side'
            },

            items: [
                {
                    xtype: 'textfield',
                    name : 'id',
                    fieldLabel: 'id',
                    hidden:true
                },    
                {
                    xtype: 'textfield',
                    name : 'title',
                    fieldLabel: 'Title'
                },
                {
                    xtype: 'textfield',
                    name : 'author',
                    fieldLabel: 'Author'
                },   
                {
                    xtype: 'textfield',
                    name : 'publisher',
                    fieldLabel: 'Publisher'
                },
                {
                    xtype: 'textfield',
                    name : 'isbn',
                    fieldLabel: 'Isbn'
                },
                {
                    xtype: 'textfield',
                    name : 'pages',
                    fieldLabel: 'Pages'
                },
                {
                    xtype: 'textfield',
                    name : 'category',
                    fieldLabel: 'Category'
                },
                {
                    xtype: 'textfield',
                    name : 'qty',
                    fieldLabel: 'Qty'
                }
            ]
        }
    ];

    this.dockedItems = [{
        xtype: 'toolbar',
        dock: 'bottom',
        id:'buttons',
        ui: 'footer',
        items: ['->', {
            iconCls: 'icon-save',
            itemId: 'save',
            text: 'Save',
            action: 'save'
        },{
            iconCls: 'icon-reset',
            text: 'Cancel',
            scope: this,
            handler: this.close
        }]
    }];

    this.callParent(arguments);
}
});

My app.js:

Ext.application({
name: 'ExtJS',

controllers: [
    'Books'
],

launch: function() {
    Ext.create('Ext.container.Viewport', {
        layout: 'fit',
        items: [
            {
                xtype: 'booklist'
            }
        ]
    });
}
});

The error "Remote exception" from store/Books.js is thrown. I don't know what can be the problem.

EDIT:

The problem is: "Error retrieving books from database". It comes from Java Controller:

@Controller

public class BookController {

private BookService bookService;

@RequestMapping(value="/books/view.action")
public @ResponseBody Map<String,? extends Object> view(@RequestParam int start, @RequestParam int limit) throws Exception {

    try{

        List<Book> books = bookService.getBookList(start,limit);

        int total = bookService.getTotalBooks();

        return ExtJSReturn.mapOK(books, total);

    } catch (Exception e) {

        return ExtJSReturn.mapError("Error retrieving books from database.");
    }
}

See also BookService.java method:

    @Transactional(readOnly=true)
public List<Book> getBookList(int start, int limit){

    return bookDAO.getBooks(start, limit);
}

    public int getTotalBooks(){

    return bookDAO.getTotalBooks();
}

See BookDAO.java methods:

    @SuppressWarnings("unchecked")
public List<Book> getBooks(int start, int limit) {

    DetachedCriteria criteria = DetachedCriteria.forClass(Book.class);

    return hibernateTemplate.findByCriteria(criteria, start, limit);
}

    public int getTotalBooks(){
    return DataAccessUtils.intResult(hibernateTemplate.find("SELECT COUNT(*) FROM books"));
}

Any idea?

Pascut
  • 3,291
  • 6
  • 36
  • 64
  • What do your server logs say? The exception event fires if the server returns an exception or if the request times out. – existdissolve Jan 21 '13 at 18:30
  • I fixed it to show the error. It says: Error retrieving books from database. That's from the java controller. I'll post it at the end of the initial post. I'll make an edit right now. – Pascut Jan 21 '13 at 18:34
  • I added some Java methods, please look at them, the method from the controller should retrieve the data from the database, that method raises the error. – Pascut Jan 21 '13 at 18:39
  • see the Console output here: http://pastebin.com/jMQKS31P – Pascut Jan 21 '13 at 18:42

1 Answers1

0

Here is the problem:

org.springframework.orm.hibernate3.HibernateQueryException: books is not mapped [SELECT COUNT(*) FROM books]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: books is not mapped [SELECT COUNT(*) FROM books]

Fixed here: https://stackoverflow.com/a/14447201/1564840

Community
  • 1
  • 1
Pascut
  • 3,291
  • 6
  • 36
  • 64