How to send Spring MVC a JSON of a formula with ExtJS (6.2.0)?

0

I'm making a Login using Spring MVC and ExtJS version 6.2.0. It does not work for me and I have already surfed without finding the solution since I pick up the username and password and supposedly send it to my Spring driver and there process the JSON Object, I show them my code to see if they can make me see the error since it does not arrive to enter the Spring controller.

My model:

Ext.define('GrupoBruce.model.Usuario', {
    extend: 'Ext.data.Model',

    alias: 'model.usuario',

    fields: [
        { name: 'acceder', type: 'boolean' },
        { name: 'accesos', type: 'auto' },
        { name: 'clave', type: 'string' },
        { name: 'estado', type: 'boolean' },
        { name: 'idUsuario', type: 'string' },
        { name: 'trabajador', type: 'auto' },
        { name: 'usu', type: 'string' }
    ]
});

My form:

Ext.define('GrupoBruce.view.login.Login', {
    extend: 'Ext.window.Window',

    xtype: 'login',

    requires: [
        'GrupoBruce.view.login.LoginController',
        'GrupoBruce.view.login.LoginModel',

        'Ext.form.Panel'
    ],

    controller: 'login',
    viewModel: {
        type: 'login'
    },

    bind: {
        title: '{titLogin}'
    },

    bodyPadding: 20,
    closable: false,
    autoShow: true,
    resizable: false,

    items: [{
            xtype: 'form',
            reference: 'formLogin',

            items: [{
                    xtype: 'textfield',
                    name: 'usu',
                    fieldLabel: 'Usuario',
                    emptyText: 'Número de DNI',
                    allowBlank: false
                }, {
                    xtype: 'textfield',
                    name: 'clave',
                    fieldLabel: 'Contraseña',
                    inputType: 'password',
                    emptyText: 'Caracteres alfanuméricos',
                    allowBlank: false
                }],
            buttons: [{
                    text: 'Ingresar',
                    formBind: true,
                    listeners: {
                        click: 'inicioSesion'
                    }
                }]
        }]
});

My ExtJS driver:

Ext.define('GrupoBruce.view.login.LoginController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.login',

    inicioSesion: function () {

        var form = this.lookupReference('formLogin');
        if (!form.isDirty()) {
            Ext.Msg.alert('Status', 'No new data to create.');
            return;
        } else if (!form.isValid()) {
            Ext.Msg.alert('Status', 'Invalid data.');
            return;
        }
        form.submit({
            url: 'validate.htm',
            method: 'POST',

            waitMsg: 'Accediendo al servidor..',

            headers: {
                'Content-Type': 'application/json'
            },
            clientValidation: true,
            submitEmptyText: true,

            success: function (form, action) {
                Ext.Msg.alert('Status', action.result.msg);
                // Set the localStorage value to true
                localStorage.setItem("sesionUsuario", true);
                // Remove Login Window
                this.getView().destroy();
                // Add the main view to the viewport
                Ext.create({
                    xtype: 'app-main'
                });
            },

            failurer: function (form, action) {
                Ext.Msg.alert('Status', action.result.msg);
            }
        });
    }

});

Spring MVC Controlled:

@ResponseBody
    @RequestMapping(value = "/validate", method = RequestMethod.POST)
    public Map<String, Object> validarUsuario(HttpServletRequest request, @RequestBody Usuario usuario) {
        Map<String, Object> map = new HashMap<>();
        usuario = su.accesoUsuario(usuario.getUsu(), new String(usuario.getClave()));
        if (usuario != null) {
            System.out.println("validado!!!...");
            map.put("success", true);
            map.put("msg", "Datos encontrados.");
            map.put("data", usuario);
        } else {
            System.out.println("No validado!!!!...");
            map.put("success", false);
            map.put("msg", "Datos no encontrados.");
        }

        return map;
    }

User Entity:

@Entity
@Table(name = "USUARIO")
public class Usuario implements java.io.Serializable {

    private String idUsuario;
    private Trabajador trabajador;
    private String usu;
    private byte[] clave;
    private boolean estado;
    private boolean acceder;
    private Set<Acceso> accesos = new HashSet<Acceso>(0);


    private String diClave;

    public Usuario() {
    }
    //getter and setter
}
    
asked by Oscar 21.07.2018 в 16:31
source

0 answers