Help about an MVC playframework error. I am using Java, Scala, HTML Javascript

0

Help, I'm using MVC playframework I want to record data from a form using AJAX by sending it to a JAVA method, but at the time of saving it marks me the following error that is shown in the following . and it does not save the data.

This is the error [{"error":"Error al guardar los datos"},{"ValidationError":"{\"fechaderegistro\":[\"This field is required\"],\"nombre\":[\"This field is required\"]}"}]

    
asked by Manuel Aguilar 30.10.2017 в 16:51
source

2 answers

-1

// == Javascript function that I execute when I click on the SAVE button on my form. function saveBusiness () {     //document.getElementById('add_reg').value= '';       $ .ajax ({         url: '@ CtrEmpresa.save',         type: 'POST',         data: $ ('#formMain') .serialize (),         dataType: 'json',         success: function (data, textStatus, jqXHR) {            // When you managed to save the company's data           console.log ('It was saved correctly');           var message = generate ('top', 'success', 'defaultTheme', jqXHR.responseText);           console.log (data);           console.log (textStatus);           console.log (jqXHR);         },         error: function (jqXHR, textStatus, errorThrown) {             // could not register            var message = generate ('top', 'error', 'defaultTheme', jqXHR.responseText);             console.log ('A papu error has been detected');             console.error (jqXHR.responseText);             console.log (textStatus);             console.log (errorThrown);         }       });       // return false; }

    
answered by 31.10.2017 в 07:50
-2

// === Java method where I must manipulate the data coming from ajax == public static Result save () {         Form boundForm = objectForm.bindFromRequest ();         List respList = new ArrayList ();         System.out.println (boundForm);         String msgErr="Please correct the information provided Thank you !!";         if (boundForm.hasErrors ()) {             respList = Utils.getErr (respList, msgErr, "ValidationError", boundForm.errorsAsJson (). toString ());             return badRequest (Json.toJson (respList));         }         Company object = boundForm.get ();         try {             String fieldNameFileFile="logo";             String extensions Valid=".jpg | .gif | .png | .jpeg";             Http.MultipartFormData.FilePart part = request (). Body (). AsMultipartFormData (). GetFile (fieldNameFile);             String fileName = part! = Null? part.getFilename (): "";             if (getLogoFile (object, extensionsValidas, part, fileName)) {                 respList = Utils.getErr (respList, msgErr, "ValidationError", boundForm.errorsAsJson (). toString ());                 return badRequest (Json.toJson (respList));             }             if (object.id == null || object.id == 0) {                 // create the object                 object.id = null; // The view is assigned a value of 0, so here it is removed so that the auto-incremented value is assigned                 object.save ();             } else {                 object.update ();                 String empresa_id_EnSession = session (). Get (USER_empresa_id);                 if (company_id_EnSession.equalsIgnoreCase (object.id + "")) {                     // Update the name of this company in the session                     session (). put (USER_company_name, object.name);                 }             }         } catch (Exception e) {             BeanValidator.setMsgFieldForDBError (e, boundForm.errors (), "");             respList = Utils.getErr (respList, msgErr, "ValidationError", boundForm.errorsAsJson (). toString ());             return badRequest (Json.toJson (respList));         }         msgErr="The data of the institution / Company was saved correctly";         respList = Utils.getErr (respList, "message", msgErr, "obj", Json.toJson (object));         return ok (Json.toJson (respList));     }     private static boolean getLogoFile (Enterprise object, String extents, Http.MultipartFormData.FilePart part, String fileName) {         if (! fileName.isEmpty ()) {             String newNombrArch = object.id + "-" + fileName;             String msgErr = File.saveFile (extentsValidas, part, fileName, newNombrArch, getAppUploadPath (), true);             if (! msgErr.isEmpty ()) {                 play.Logger.debug ("msgErr +" + msgErr);                 flash ("error", msgErr);                 // Return to the view so that error messages are displayed                 return true;             }             object.logo = newNombrArch;         } else {             if (object.id! = null) {                 // retrieve from the BD the name of the logo file                 Company objEmpresa = Empresa.find ("" + objeto.id);                 object.logo = objEmpresa.logo;             }         }         return false;     }

    
answered by 30.10.2017 в 18:24