Akshatha
Akshatha

Reputation: 319

How to call java method in javascript in sencha?

I am new to sencha touch. I want to call my Java method in my .js file. Onclick of the button i want my java method to be called.

The java method I want to call is this:

//UserManager.java
public class UserManager extends BaseManager{
...
 public boolean validateUser(String email)
{
    UserDAO userDAO = new UserDAO();
    boolean result = false;
    try {
        result = userDAO.validateUser(email);
    } catch (SQLException e) {
        log.error(e.getMessage(),e.getCause());
    }
    return result;

}
}

My sencha javascript file looks like this:

{
   xtype: 'button',
   text: 'Login',
   handler: function() {
//something like this i want:
                        //str=UserManager.validateUser('[email protected]')
                        //alert(str);
                         if(UserManager.validateUser('[email protected]'))
                         polling.Viewport.setActiveItem('QPanel', {type:'slide', direction:'left'});
                        else
                        alert("failed");
                    }
                },

Please let me know how do I call the java method inside this javascript in sencha? Thanks.

Upvotes: 0

Views: 2208

Answers (1)

kandarp
kandarp

Reputation: 5047

in my project(we are using extjs), I am using spring mvc. So, I have all java methods in controller. So, when I need to call it from javascript, we do it through

  • Ajax call :

    Ext.Ajax.request({
        url: 'getCustomerList',
        success: function(result, action){
    
        },
        failure: function(result, action){
    
        },
        params: { customerName: Ext.getCmp('name').getValue() }
    

    });

  • Anchor tag:

    autoEl:{ tag: 'a', href: 'getCustomerList', cn : 'customers' }

in both cases, getCustomerList will map with spring's controller's RequestMapping method.

Upvotes: 1

Related Questions